title: "The connection was closed unexpectedly" sending to an HTTP 0.9 IP Phone
body: <p>I am new to C# and I am trying to perform a GET request to an IP phone on my network to remotely dial a number. I am receiving an exception and I am unsure how I can establish why, as I cannot retrieve any error code. This is the code I am using:-</p>
  
  <pre><code>// Create a new HttpClient instance
  var client = new HttpClient();
  
  // Command to dial number
  string dial = "http://xxx.xxx.x.x/command.htm?number=4553535345354";
  
  try
  {
      // Response
      HttpResponseMessage response = new HttpResponseMessage();
      response = await client.GetAsync(dial);
  
      if (response.IsSuccessStatusCode)
      {
          // Do other things
      }
      else
      {
          MessageBox.Show(response.StatusCode.ToString());
      }
  }
  catch (Exception err)
  {
      MessageBox.Show("Could not call: " + err.Message);
  }
  </code></pre>
  
  <p>When I run this code I receive the caught exception with message "An error occurred while sending this request". The only other additional information I can see regarding the exception is "A first chance exception of type 'System.Net.Http.HttpRequestException' occurred in mscorlib.dll"</p>
  
  <p><strong>* Updated *</strong></p>
  
  <hr>
  
  <hr>
  
  <blockquote>
    <p>Could not call: System.Net.Http.HttpRequestException: An error
    occurred while sending the request. ---> System.Net.WebException: The
    underlying connection was closed: The connection was closed
    unexpectedly.</p>
    
    <p>at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult
    asyncResult)</p>
    
    <p>at
    System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)</p>
    
    <p>--- End of inner exception stack trace ---</p>
    
    <p>at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)</p>
    
    <p>at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)</p>
    
    <p>at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()</p>
    
    <p>at AutoDialer.Form2.d__0.MoveNext() in
    c:\Form2.cs:line 175</p>
  </blockquote>
  
  <p>** Updated 26/14 Fiddler Results **</p>
  
  <pre><code>HTTP/1.1 302 Moved Temporarily Location
  </code></pre>
  
  <p>Protocol Violation Report:-</p>
  
  <pre><code>79  The Server did not return properly-formatted HTTP Headers. Maybe missing altogether (e.g. HTTP/0.9), maybe only \r\r instead of \r\n\r\n?
  </code></pre>
  
  <p>Extended Checks:-</p>
  
  <pre><code>182 [HTTPLint] With rare exceptions, servers MUST include a DATE response header. RFC2616 Section 14.18
  </code></pre>