title: Error is thrown when using GET in a REST API client
body: <p>I'm consuming a web service in REST, I'm using Windows Forms, C#.</p>
  <p>When I am running the line</p>
  <pre><code>HttpWebResponse response = (HttpWebResponse) request.GetResponse ();
  </code></pre>
  <p>I get an error</p>
  <blockquote>
  <p>InnerException = {&quot; Cannot read data from the transport connection: An existing connection was forced to close by the remote host. &quot;}</p>
  </blockquote>
  <p>If anyone can help me stay, I will be grateful.</p>
  <p>Here is the code:</p>
  <pre class="lang-cs prettyprint-override"><code>public string Get()
  {
      string errorMessage;
      string StrResponseValue = string.Empty;
      try 
      {
          HttpClient client = new HttpClient();
          client.BaseAddress = new Uri(EndPoint);
  
          // Add an Accept header for JSON format.
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(&quot;application/json&quot;));
  
          // List data response.
          HttpResponseMessage response = client.GetAsync(urlParameters).Result;  // Blocking call! Program will wait here until a response is received or a timeout occurs.
          if (response.IsSuccessStatusCode)
          {
              // Parse the response body.
              var dataObjects = response.Content.ReadAsAsync&lt;IEnumerable&lt;DataObject&gt;&gt;().Result;  // Make sure to add a reference to System.Net.Http.Formatting.dll
              foreach (var d in dataObjects)
              {
              //  Console.WriteLine(&quot;{0}&quot;, d.Name);
              }
          }
          else
          {
              Console.WriteLine(&quot;{0} ({1})&quot;, (int)response.StatusCode, response.ReasonPhrase);
          }  
          client.Dispose();
      }
      catch(Exception ex)
      {
        errorMessage= ex.Message;
      }
      
      return StrResponseValue;
  }
  </code></pre>