title: HTTPWebRequest GET request causing SSL connection issue
body: <p>I am trying to connect to a RESTful API and when I access the URL from my browser I get an error stating I am missing headers which is what I was expecting to get. When I connect to the same URL using the below code I get an error stating "The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Authentication failed because the remote party has closed the transport stream". If I use the same code and change the URL to Google.com it works fine and to add to the mystery the connection I make to the API URL from my browser will generate an entry in the Apache logs on the API server, but the below code doesn't. Does anyone have any ideas why I would get that error? </p>
  
  <pre><code>        var httpWebRequest = (HttpWebRequest)WebRequest.Create("HTTPS://URL.COM");
  
          httpWebRequest.ContentType = "application/json";
          httpWebRequest.Method = "GET";
  
          string html = string.Empty;
          try
          {
              HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
              string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
  
  
  
              Response.Write(responseString);
          }
          catch (Exception ex)
          {
              Response.Write(ex.ToString());
          }
  </code></pre>
  
  <p>UPDATE: I tried using HttpClient and got the same results:</p>
  
  <pre><code>        HttpClient client = new HttpClient();
          client.BaseAddress = new Uri("https://url.com/");
  
          // Add an Accept header for JSON format.
          client.DefaultRequestHeaders.Accept.Add(
              new MediaTypeWithQualityHeaderValue("application/json"));
  
          HttpResponseMessage response = client.GetAsync("v1/person").Result;
  
          if (response.IsSuccessStatusCode)
          {
              Response.Write(response);
  
          }
          else
          {
              Response.Write(response);
          }
  </code></pre>
  
  <p>UPDATE 2: The below line of code seems to fix the problem. I am awaiting confirmation now. I am still a little baffled why this was required though. </p>
  
  <pre><code>    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
  </code></pre>