C# 程序错误"the requested security protocol is not supported"



我使用了下面的代码

try
{
ServicePointManager.ServerCertificateValidationCal  lback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
WebRequest req = WebRequest.Create(site);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = Encoding.UTF8.GetBytes("data=" + "null");
req.ContentLength = bytes.Length;
Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
WebResponse resp = req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
MessageBox.Show(sr.ReadToEnd().Trim());
}
catch (Exception exc)
{
MessageBox.Show(exc.Message.ToString());
}

该程序在我的计算机中运行没有错误,但是在我客户的计算机中运行时显示以下错误 "不支持请求的安全协议">

在继续中,我将代码更改为以下内容

try
{
WebRequest req = WebRequest.Create(site);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = Encoding.UTF8.GetBytes("data=" + "null");
req.ContentLength = bytes.Length;
Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
WebResponse resp = req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());

MessageBox.Show(sr.ReadToEnd().Trim());
}
catch (Exception exc)
{
MessageBox.Show(exc.Message.ToString());
}

但又是错误。

我客户的电脑是 DonNet 4 的 Win7。

你设置下面的代码并测试

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls

相关内容

最新更新