我的客户向我报告了他们的 SSL 和 Internet Explorer 的问题。他们表示,在访问该 URL 时会遇到信任问题。
我正在通过 HTTPS 访问 JSON。该网站位于一台服务器上,我正在本地计算机上使用控制台应用程序。我试图绕过 SSL 证书,但是我的代码仍然失败。
我可以改变 HttpWebRequest 来解决这个问题吗?
我使用以下代码收到此错误:
// You must change the URL to point to your Web server.
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "GET";
req.AllowAutoRedirect = true;
// allows for validation of SSL conversations
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
WebResponse respon = req.GetResponse();
Stream res = respon.GetResponseStream();
string ret = "";
byte[] buffer = new byte[1048];
int read = 0;
while ((read = res.Read(buffer, 0, buffer.Length)) > 0)
{
//Console.Write(Encoding.ASCII.GetString(buffer, 0, read));
ret += Encoding.ASCII.GetString(buffer, 0, read);
}
return ret;
我必须启用其他安全协议版本才能解决该问题:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)