I am using C#, .Net framework 4.0 and trying to do HttpWebRequest for Http Basic Authentication and getting below error:
Inner Exception 1:
IOException: Authentication failed because the remote party has closed the transport stream.
I am using below 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();
}
Error during GetResponse().
I tried all the references in SO:
But of no use, still getting same error. Any problem in my code?