c# – 为ServicePointManager.SecurityProtocol设置每个请求值

前端之家收集整理的这篇文章主要介绍了c# – 为ServicePointManager.SecurityProtocol设置每个请求值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > Set the SecurityProtocol (Ssl3 or TLS) on the .net HttpWebRequest per request6
在c#中,我可以为SSL3或TLS设置静态值,例如
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

要么:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

但是(我相信)这将影响我应用程序中的所有将来的HttpWebRequest对象.

有没有办法为给定的HttpWebRequest或至少为给定的URI设置这个?

注意我已经看到这个:

Uri uri = new Uri(url);
ServicePoint sp = ServicePointManager.FindServicePoint(uri);

但是ServicePoint没有SecurityProtocol属性.

目前,我想我将必须在创建一个新的HttpWebRequest之前设置静态全局属性.

这不觉得正确,也意味着:

>我必须确保多个线程不是在同一时间这样做.
>我不知道这个设置是什么时候被使用的(即当我调用webRequest.GetResponse()来访问ServicePointManager.SecurityProtocol并绑定到该URI时)?

解决方法

实现这一点已经在这里被覆盖:

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

和这里:

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

确认我的恐惧有些用户似乎正在旋转一个单独的应用程序域来解决这个问题.我仍然认为一些线程锁定可能是可能的,如果它被定义在什么时候绑定到特定的Web请求对象的位置.

原文链接:https://www.f2er.com/csharp/96887.html

猜你在找的C#相关文章