Why is my Initial call in RestSharp really slow? but others after are very fast

后端 未结 4 1199
难免孤独
难免孤独 2021-01-04 08:03

I am making calls to a WEB API using RESTSHARP and they work fine. However, the Initial call to the API (regardless of what call it is) can sometimes take up to 10 seconds t

4条回答
  •  日久生厌
    2021-01-04 08:43

    I had attempted @skrause's answer, but it wasn't work for me. I spend much time, and finaly I solved it. This my sulotion.

    public class SimpleWebProxy : IWebProxy
    {
        public ICredentials Credentials { get; set; }
    
        public Uri GetProxy(Uri destination)
        {
            return destination;
        }
    
        public bool IsBypassed(Uri host)
        {
            // if return true, service will be very slow.
            return false;
        }
    
        private static SimpleWebProxy defaultProxy = new SimpleWebProxy();
        public static SimpleWebProxy Default
        {
            get
            {
                return defaultProxy;
            }
        }
    }
    
    var client = new RestClient();
    client.Proxy = SimpleWebProxy.Default;
    

提交回复
热议问题