使用HttpWebRequest在C#中的request.GetResponse()期间身份验证失败

使用HttpWebRequest在C#中的request.GetResponse()期间身份验证失败,c#,asp.net,authentication,httpwebrequest,httpwebresponse,C#,Asp.net,Authentication,Httpwebrequest,Httpwebresponse,我正在使用C#,.Net framework 4.0,并尝试对Http基本身份验证执行HttpWebRequest,出现以下错误: Inner Exception 1: IOException: Authentication failed because the remote party has closed the transport stream. 我正在使用以下代码: string svccessenties=Convert.ToBase64String(System.Text.Enc

我正在使用C#,.Net framework 4.0,并尝试对Http基本身份验证执行HttpWebRequest,出现以下错误:


Inner Exception 1:
IOException: Authentication failed because the remote party has closed the transport stream.
我正在使用以下代码:


string svccessenties=Convert.ToBase64String(System.Text.Encoding.GetEncoding(“ISO-8859-1”).GetBytes(userName+”:“+password));
HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(url);
添加(“授权”、“基本”+SVC凭证);
ServicePointManager.SecurityProtocol=SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
使用(HttpWebResponse=(HttpWebResponse)request.GetResponse())
使用(Stream=response.GetResponseStream())
使用(StreamReader=新StreamReader(stream))
{
html=reader.ReadToEnd();
}

GetResponse()期间出错

我尝试了所有的参考资料,所以:


但是没有用,仍然得到同样的错误。我的代码中有任何问题吗?

此问题在更改ServicePointManager.SecurityProtocol后得到解决,如下所示:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;

由于Tls 1.1、1.2在.net framework 4.0中无法直接在System.net中使用。

此问题在更改ServicePointManager.SecurityProtocol后得到解决,如下所示:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;
由于Tls 1.1、1.2在.net framework 4.0中无法直接在System.net中提供