【问题标题】:Setting per request value for ServicePointManager.SecurityProtocol [duplicate]为 ServicePointManager.SecurityProtocol 设置每个请求值 [重复]
【发布时间】:2014-10-15 14:10:00
【问题描述】:

在 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?)。

【问题讨论】:

    标签: c# ssl httpwebrequest


    【解决方案1】:

    意识到这里已经涵盖了这一点:

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

    这里:

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

    证实了我的恐惧。一些用户似乎正在建立一个单独的应用程序域来解决这个问题。我仍然认为,如果在设置绑定到特定 Web 请求对象的时间点明确定义了某些线程锁定,则它可能是可能的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-29
      • 2016-03-31
      • 2020-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-02
      • 1970-01-01
      相关资源
      最近更新 更多