我已阅读以下 2 篇文章并尝试实施相同的文章。
我的代码是这个,超时发生在这里
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.ContentType = "multipart/form-data; boundary=" + boundary;
wr.Method = "POST";
wr.KeepAlive = false;
wr.CookieContainer = cookieJar;
wr.Proxy = null;
wr.ServicePoint.ConnectionLeaseTimeout = 5000;
Stream rs = wr.GetRequestStream(); // -> Time out error occurs here
My code using that as a sample
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.ContentType = "multipart/form-data; boundary=" + boundary;
wr.Method = "POST";
wr.KeepAlive = false;
wr.CookieContainer = cookieJar;
wr.Timeout = 5000;
wr.Proxy = null;
wr.ServicePoint.ConnectionLeaseTimeout = 5000;
wr.ServicePoint.MaxIdleTime = 5000;
Stream rs = wr.GetRequestStream(); //-->Time out error
任何线索都会有所帮助。有时我可以通过 1 个请求,而所有其他请求都失败或一切都失败了。我正在发布到 HTTPS 站点。使用 Fiddler 运行时没有问题
更新 1:我尝试遵循 zbugs 的想法,但这导致了同样的问题。第一个请求通过后续请求失败。我正在关闭所有响应流以及在我的请求对象上调用 abort。