几个 POST 请求后 GetResponseAsync 超时
GetResponseAsync timeout after a few POST request
我正在用 C# 发出一个 POST 请求,如下所示:
var request = WebRequest.Create("http://xxx.xxx.xxx.xxx:8080/xxx/obj/data/xxx/commands/GET");
request.ContentType = "application/json";
((HttpWebRequest)request).Accept = "application/json";
request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en");
NetworkCredential myNetworkCredentials = new NetworkCredential("myUser", "MyPass");
CredentialCache myCredentialCache = new CredentialCache
{
{ link, "Basic", myNetworkCredentials }
};
request.Credentials = myCredentialCache;
request.PreAuthenticate = true;
request.Method = "POST";
await request.GetResponseAsync();
当我使用 Postman 检查响应时,一切正常,每次发送请求时它都有效。
但是以编程方式,在 7-8 次之后,await request.GetResponseAsync(); 给了我一个异常,"The Operation has timed out".
我不知道如何检查这个,在邮递员中一切正常,但在应用程序中经过几次测试后失败了。我能做什么?
默认情况下,您在启动应用程序时只有 10 个连接限制。所以你需要在 Uri 中为你的请求设置这个
ServicePoint sp = ServicePointManager.FindServicePoint(uri);
sp.ConnectionLimit = 1000;
ServicePointManager.DefaultConnectionLimit = 1000;
我正在用 C# 发出一个 POST 请求,如下所示:
var request = WebRequest.Create("http://xxx.xxx.xxx.xxx:8080/xxx/obj/data/xxx/commands/GET");
request.ContentType = "application/json";
((HttpWebRequest)request).Accept = "application/json";
request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en");
NetworkCredential myNetworkCredentials = new NetworkCredential("myUser", "MyPass");
CredentialCache myCredentialCache = new CredentialCache
{
{ link, "Basic", myNetworkCredentials }
};
request.Credentials = myCredentialCache;
request.PreAuthenticate = true;
request.Method = "POST";
await request.GetResponseAsync();
当我使用 Postman 检查响应时,一切正常,每次发送请求时它都有效。
但是以编程方式,在 7-8 次之后,await request.GetResponseAsync(); 给了我一个异常,"The Operation has timed out".
我不知道如何检查这个,在邮递员中一切正常,但在应用程序中经过几次测试后失败了。我能做什么?
默认情况下,您在启动应用程序时只有 10 个连接限制。所以你需要在 Uri 中为你的请求设置这个
ServicePoint sp = ServicePointManager.FindServicePoint(uri);
sp.ConnectionLimit = 1000;
ServicePointManager.DefaultConnectionLimit = 1000;