没有代理的 HttpWebRequest 非常慢

HttpWebRequest is very slow without proxy

我写这段代码是为了从外部读取数据url。

request.GetResponse() 需要一分多钟才能 运行 并且非常慢。

string responseContent;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://payroll/PayrollReport/getPaymentHistory?number=13990701&reason=21&username=8062122&Credential=E5ohh/BZDBWAQBE2R8tmbUSiVGJ2/ndI3AmqDiCMBylOIK/eAdRZog==");
request.Method = "GET";
request.Proxy = GlobalProxySelection.GetEmptyWebProxy(); // null;
System.Net.ServicePointManager.Expect100Continue = false;
ServicePointManager.UseNagleAlgorithm = false;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    using (Stream responseStream = response.GetResponseStream())
    {
        using (StreamReader sr = new StreamReader(responseStream))
            responseContent = sr.ReadToEnd();
    }
}

但是当用 post 调用此 url 时,人非常快 运行 不到 1000 毫秒。

在网络捕获中,仅位置 属性 在 c# 和 post man

之间是不同的

请帮我减慢代码执行速度

我在代码中添加了AspxAutoDetectCookieSupport=1,问题解决了

The AspxAutoDetectCookieSupport=1 querystring is added automatically by ASP.NET during the cookie support detection phase. Since cookieless attribute in the web.config file is set to "AutoDetect", the ASP.NET runtime tries to detect whether the user's browser supports cookies, and the querystring parameter is added during that process. If cookies are supported, the Session ID is kept in a cookie, and if not the Session ID is sent in the Url of all future requests by that user.

Uri target = new Uri("http://payroll/PayrollReport/getPaymentHistory?number=13990701&reason=21&username=8062122&Credential=E5ohh/BZDBWAQBE2R8tmbUSiVGJ2/ndI3AmqDiCMBylOIK/eAdRZog==");

string responseContent;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(target);

request.CookieContainer = new CookieContainer();         
request.CookieContainer.Add(new Cookie("AspxAutoDetectCookieSupport", "1") { Domain = target.Host });

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    using (Stream responseStream = response.GetResponseStream())
    {
        using (StreamReader sr = new StreamReader(responseStream))
            responseContent = sr.ReadToEnd();
    }
}