我想發送多個WebRequest
。我使用了Parallel.For
循環來做到這一點,但循環運行一次,第二次在獲得響應時出現錯誤。並行發送多個WebRequest。對於
錯誤:
The operation has timed out
代碼:
Parallel.For(0, 10, delegate(int i) {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
new Uri("http://www.mysite.com/service"));
string dataToSend = "Data";
byte[] buffer = System.Text.Encoding.GetEncoding(1252).
GetBytes(dataToSend);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = buffer.Length;
request.Host = "www.mysite.com";
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
});
它給你一個錯誤信息?真?你想問一些特別的問題嗎? –
而錯誤是...? – Icarus
什麼是例外,它在哪裏發生?你確定服務器實際上沒有超時嗎? –