title: Authentication failed during request.GetResponse() in C# using HttpWebRequest
body: <p>I am using C#, .Net framework 4.0 and trying to do HttpWebRequest for Http Basic Authentication and getting below error:</p>
  
  <pre><code>
  Inner Exception 1:
  IOException: Authentication failed because the remote party has closed the transport stream.</code></pre>
  
  <p>I am using below code:</p>
  
  <p><pre><code>
  string svcCredentials = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(userName + ":" + password));
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  request.Headers.Add("Authorization", "Basic " + svcCredentials);
  ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
  using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  using (Stream stream = response.GetResponseStream())
  using (StreamReader reader = new StreamReader(stream))
  {
      html = reader.ReadToEnd();
  }
  </pre></code></p>
  
  <p>Error during GetResponse().</p>
  
  <p>I tried all the references in SO:</p>
  
  <p><a href="https://stackoverflow.com/questions/35621686/authentication-failed-because-the-remote-party-has-closed-the-transport-stream-e">Authentication failed because the remote party has closed the transport stream exception when getting a response from webservice</a></p>
  
  <p><a href="https://stackoverflow.com/questions/19639846/failure-on-httpwebrequest-with-inner-exception-authentication-failed-because-the">Failure on HttpWebrequest with inner exception Authentication failed because the remote party has closed the transport stream</a></p>
  
  <p>But of no use, still getting same error. Any problem in my code?</p>