zl程序教程

您现在的位置是:首页 >  后端

当前栏目

c# HttpWebRequest 解决 请求HTTPS慢

c#HTTPS 解决 请求 HttpWebRequest
2023-09-14 09:07:52 时间

其实就几行代码

if (strUrl.StartsWith("https", StringComparison.OrdinalIgnoreCase))
            {
                request.Credentials = CredentialCache.DefaultCredentials;
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                request.ProtocolVersion = HttpVersion.Version11;

                ServicePointManager.CheckCertificateRevocationList = true;
                ServicePointManager.DefaultConnectionLimit = 100;
                ServicePointManager.Expect100Continue = false;
            }

 app.config增加

 <system.net>   
    <defaultProxy   
        enabled="false"   
        useDefaultCredentials="false" >   
      <proxy/>   
      <bypasslist/>   
      <module/>   
    </defaultProxy>   
  </system.net>