Setting per request value for ServicePointManager.SecurityProtocol [duplicate]

可紊 提交于 2020-01-01 04:06:11

问题


In c# I am able to set a static value for SSL3 or TLS, e.g.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

Or:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

But (I believe) this will affect all future HttpWebRequest objects in my application.

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);

But ServicePoint does not have a SecurityProtocol property.

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:

  • I have to make sure multiple threads are not doing this at the same time.
  • I am not sure by what point this setting has been 'used' (i.e. is it when I call webRequest.GetResponse() that the ServicePointManager.SecurityProtocol is accessed and bound to that URI?).

回答1:


Realised this has been covered here:

How to use SSL3 instead of TLS in a particular HttpWebRequest?

And here:

Set the SecurityProtocol (Ssl3 or TLS) on the .net HttpWebRequest per request

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.



来源:https://stackoverflow.com/questions/26384692/setting-per-request-value-for-servicepointmanager-securityprotocol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!