且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

每个请求更改安全协议(HttpClient)

更新时间:2023-02-05 12:36:03

你不需要设置 it。

您可以使用:

using System.Net;
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

附加说明:


  • .Net 4.5需要因为Tls12不是默认协议。

  • 只需在应用程序中编写一次上述代码。 (例如,在Web应用程序中的Global.asax> Application_Start或Winforms应用程序中的等效内容)

  • 对于.Net 4.6及更高版本,Tls12是默认协议,因此不需要