title: The underlying connection was closed. An unexpected error occurred on a send
body: <p>I am trying to connect to an API. I will preface this and say this is a project we were working on months ago, and it was working, at least in the sense i could reach out and get the data from the API fine. We put the project on hold for a couple months, come back to it, and now the connection to this one API no longer works. In the project we are connecting to 2 API's and the second API connections work fine still. I have attempted to recreate the request using the same headers in Postman and it works fine. I have had this issue before, and adding the line:</p>
  
  <pre><code>ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
  </code></pre>
  
  <p>Solved it for me in the past, but i have that code in the method and it still fails now. </p>
  
  <p><strong>Below is the full method:</strong></p>
  
  <pre><code>var encodedData = System.Convert.ToBase64String(
                                      System.Text.Encoding.GetEncoding("ISO-8859-1")
                                      .GetBytes("XXXXXXXXXXXXXXXXXXX:")
                                  ); 
  
  string headerString = "Basic " + encodedData;
  
  var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://xxxxxxxxxxxxxxx);
  
  httpWebRequest.ContentType = "application/json";
  httpWebRequest.Method = "GET";
  httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, headerString);
  httpWebRequest.KeepAlive = false;    
  
  ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
  //ServicePointManager.SecurityProtocol = (SecurityProtocolType)768;   
  //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
  
  Console.WriteLine("Protocol: " + ServicePointManager.SecurityProtocol);
  
  //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
  //                           SecurityProtocolType.Tls11 |
  //                           SecurityProtocolType.Tls12;
  
  var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  
  using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
  {
      var result = streamReader.ReadToEnd();   
  
      writelog("Result: " + result);
  }
  </code></pre>
  
  <p>Not sure if this helps, but when i try to analyze the traffic in Fiddler, i can see the request coming out of Postman fine, but when i run the above code i never get any traffic leaving my network. Just alot of traffic from localhost to /vshub/XXXXXXXXXXX. I have also tried other permutations of the <code>ServicePointManager.SecurityProtocol</code> as you can see from the commented out code, but none have worked.</p>
  
  <p>I am at wits end trying to solve this. 
  Any help would be appreciated! 
  Oh, i am on <code>runtime 4.0</code> and <code>framework 4.6</code>.</p>
  
  <p>UPDATE: Ran the code on alternate machines using the same runtime and framework and it works fine. It seems more and more likely to be a Firewall issue on my local machine. </p>
  
  <p>Thanks so much in advance!</p>