简体   繁体   English

慢的Http使用C#获取请求

[英]Slow Http Get Requests With C#

I currently have a python server running that handles many different kinds of requests and I'm trying to do this using C#. 我目前正在运行一个处理许多不同类型请求的python服务器,而我正在尝试使用C#进行此操作。 My code is as follows: 我的代码如下:

try
{
   ServicePointManager.DefaultConnectionLimit = 10;
   System.Net.ServicePointManager.Expect100Continue = false;
   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
   request.Proxy = null;
   request.Method = "GET";

   using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
   {
      response.Close();
   }

}
catch (WebException e)
{
   Console.WriteLine(e);
}

My first get request is almost instant but after that, the time it takes for one request to go through is almost 30 seconds to 1 min. 我的第一个get请求几乎是即时的,但是此后,一个请求通过的时间几乎是30秒到1分钟。 I have researched everywhere online and tried to change the settings to make it run faster but it can't seem to work. 我在网上到处进行了研究,并尝试更改设置以使其运行更快,但似乎无法正常工作。 Are there anymore settings that I could change to make it faster? 是否有其他设置可以更改以使其更快?

By using my psychic debugging skills I guess your server only accepts one connection at the time. 通过使用我的心理调试技能,我猜您的服务器当时仅接受一个连接。 You do not close your request, so you connection is kept alive. 您没有关闭请求,因此连接保持活动状态。 Keep alive attribute. 保持活动属性。 The server will accept new connection when you current one is closed, which is default 100000ms or the server timeout. 当前关闭时,服务器将接受新连接,默认为100000ms或服务器超时。 In your case I guess 30 to 60 seconds. 在您的情况下,我猜是30到60秒。 You can start by setting the keepalive attribe to false. 您可以先将keepalive属性设置为false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM