【发布时间】:2014-10-18 18:54:46
【问题描述】:
我目前正在运行一个 python 服务器来处理许多不同类型的请求,并且我正在尝试使用 C# 来执行此操作。我的代码如下:
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);
}
我的第一个获取请求几乎是即时的,但在那之后,一个请求通过的时间几乎是 30 秒到 1 分钟。我在网上到处搜索并尝试更改设置以使其运行得更快,但似乎无法正常工作。是否还有其他设置可以更改以加快速度?
【问题讨论】:
-
HttpClient 更容易使用,你应该试试。