每个请求的值设置为ServicePointManager.SecurityProtocol [英] Setting per request value for ServicePointManager.SecurityProtocol
问题描述
在C#中,我能为SSL3或TLS,如:
In c# I am able to set a static value for SSL3 or TLS, e.g.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
或者
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
但(我相信),这将影响未来所有的HttpWebRequest对象在我的应用程序。
But (I believe) this will affect all future HttpWebRequest objects in my application.
有没有一种方法来设置此为给定的HttpWebRequest或至少一个给定的URI
Is there a way to set this for a given HttpWebRequest or at least for a given URI?
请注意我已经看到了这一点?
Note I have seen this:
Uri uri = new Uri(url);
ServicePoint sp = ServicePointManager.FindServicePoint(uri);
但是的ServicePoint不具有SecurityProtocol属性
But ServicePoint does not have a SecurityProtocol property.
目前我想我将不得不只是静态全局属性设置创建一个新的HttpWebRequest之前。
At present I am thinking I will have to just set the static global property prior to creating a new HttpWebRequest.
这感觉不对,这也意味着
This doesn't feel right and it also means:
- 我必须确保多个线程不会在同一时间做这个
- 。我不知道由什么点这个设置已经被拿来主义(即是,当我打电话webRequest.GetResponse(),该ServicePointManager.SecurityProtocol访问和绑定到URI?)。
推荐答案
已实现这已经在这里涵盖:
Realised this has been covered here:
的How在特定使用代替TLS SSL3 ?HttpWebRequest的
这里:
的设置每个申请在.NET的HttpWebRequest的SecurityProtocol(SSL3或TLS)
Set the SecurityProtocol (Ssl3 or TLS) on the .net HttpWebRequest per request
确认我的恐惧。一些用户似乎纺一个单独的应用程序域来解决这个问题。我仍然认为,如果它是在什么点的设置绑定到特定的Web请求对象明确界定有可能与一些螺纹的锁固。
Confirming my fears. Some users appear to be spinning up a separate app domain to work around this. I still think it might be possible with some thread locking if it was well defined at what point the setting is bound to a particular web request object.
这篇关于每个请求的值设置为ServicePointManager.SecurityProtocol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!