How to perform a fast web request in C#

前端 未结 4 462
夕颜
夕颜 2020-12-16 09:59

I have a HTTP based API which I potentially need to call many times. The problem is that I can\'t get the request to take less than about 20 seconds, though the same reques

4条回答
  •  粉色の甜心
    2020-12-16 10:38

    Does your site have an invalid SSL cert? Try adding this

    ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AlwaysAccept);
    
    //... somewhere AlwaysAccept is defined as:
    
    using System.Security.Cryptography.X509Certificates;
    using System.Net.Security;
    
    public bool AlwaysAccept(object sender, X509Certificate certification, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
        return true;
    }
    

提交回复
热议问题