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

南笙酒味 提交于 2019-12-04 01:26:09
skrause

It's most likely the network settings causing this problem. I recently had the same issue and it turned out that when using HttpWebRequest or RestSharp it was trying some auto configuration to look for a proxy server.

Open the network settings in Internet Explorer and disable auto configuration for the local network. In my case this resolved the delay for the first request in RestSharp as well.

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;

Tried to get rid of the auto configuration to look for a proxy server with this

System.Net.WebRequest.DefaultWebProxy = null;

If You use winforms etc. in app.config after connectionstrings:

<system.net>
  <defaultProxy enabled="true">
    <proxy usesystemdefault="True"/>
  </defaultProxy>
</system.net>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!