C#模拟post请求调用request.GetResponse()超时,报 System.Net.WebException: The operation has timed out.

C#模拟post请求调用request.GetResponse()超时,报 System.Net.WebException: The operation has timed out.

  • 解决方法1:

设置:
request.ServicePoint.Expect100Continue = false;

  • 解决方法2,尝试使用using
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
    return reader.ReadToEnd();
}
  • 解决方法3:

设置:System.Net.ServicePointManager.DefaultConnectionLimit = 200;

  • 解决方法4:

设置如下两个属性

request.Timeout = Timeout.Infinite;
request.KeepAlive = true;

你可能感兴趣的:(C#)