简体   繁体   中英

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#. 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. 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. In your case I guess 30 to 60 seconds. You can start by setting the keepalive attribe to false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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