How to perform a fast web request in C#

前端 未结 4 468
夕颜
夕颜 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:39

    This problem is similar to another post on StackOverflow: Stackoverflow-2519655(HttpWebrequest is extremely slow)

    Most of the time the problem is the Proxy server property. You should set this property to null, otherwise the object will attempt to search for an appropriate proxy server to use before going directly to the source. Note: this property is turn on by default, so you have to explicitly tell the object not to perform this proxy search.

    request.Proxy = null;
    using (var response = (HttpWebResponse)request.GetResponse())
    {
    }
    

提交回复
热议问题