C# 如何让 System.Web.HttpWebRequest 对象使用 SSL 2.0?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/169222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:29:54  来源:igfitidea点击:

How do you get a System.Web.HttpWebRequest object to use SSL 2.0?

c#.netsslhttpwebrequest

提问by Dylan Bennett

I don't know if I have all the information needed to phrase this question well, so bear with me.

我不知道我是否拥有很好地表达这个问题所需的所有信息,所以请耐心等待。

I have a local web page (local meaning 192.168.*) that is protected with a self-signed SSL cert. I'm trying to access this page using a System.Net.HttpWebRequest object, but I'm running into a weird problem.

我有一个受自签名 SSL 证书保护的本地网页(本地意思是 192.168.*)。我正在尝试使用 System.Net.HttpWebRequest 对象访问此页面,但遇到了一个奇怪的问题。

If this page is accessed in Internet Explorer with the "Use SSL 2.0" option turned off, the browser returns back an error as if it can't establish a connection. (In other words, a browser connection error, as opposed to a server-sent error.) If the "Use SSL 2.0" option is turned on, the page works fine and you get the standard warning that this is a self-signed cert, do you want to continue, etc. (Oddly enough, Firefox, which supposedly does not have SSL 2.0 turned on, works just fine.)

如果在“使用 SSL 2.0”选项关闭的情况下在 Internet Explorer 中访问此页面,浏览器将返回一个错误,就好像它无法建立连接一样。(换句话说,浏览器连接错误,而不是服务器发送的错误。)如果打开“使用 SSL 2.0”选项,页面工作正常,您会收到标准警告,表明这是自签名证书,你想继续吗,等等(奇怪的是,Firefox,据说没有开启 SSL 2.0,工作得很好。)

Now my problem is that I'm trying to access this page with an HttpWebRequest object and the error it's returning back is that the connection has been unexpectedly closed, just like the error IE throws when "Use SSL 2.0" is turned off. (I already have code in place to ignore the fact that it's a self-signed cert, but it's not even getting that far.)

现在我的问题是我正在尝试使用 HttpWebRequest 对象访问此页面,它返回的错误是连接意外关闭,就像关闭“使用 SSL 2.0”时 IE 抛出的错误一样。(我已经有代码可以忽略它是自签名证书的事实,但它甚至还没有那么远。)

How do I get the System.Net.HttpWebRequest to, well, "Use SSL 2.0" when it's making its request?

我如何让 System.Net.HttpWebRequest 在发出请求时“使用 SSL 2.0”?

采纳答案by Bittercoder

I've hit this issue myself when dealing with Ssl3, though I'm not sure if the same advice would work for SSL2?

在处理 Ssl3 时,我自己也遇到了这个问题,但我不确定同样的建议是否适用于 SSL2?

To work around the issue I set the Ssl3 flag on the security protocol like so:

为了解决这个问题,我在安全协议上设置了 Ssl3 标志,如下所示:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

Check out these links for more details:

查看这些链接了解更多详情:

system.net.servicepointmanager.securityprotocol on MSDN

MSDN 上的 system.net.servicepointmanager.securityprotocol

security protocol enumeration on MSDN

MSDN上的安全协议枚举

They might point you in the right direction if you're lucky :)

如果你幸运的话,他们可能会为你指明正确的方向:)