Tôi muốn gửi nhiều WebRequest
. Tôi sử dụng một vòng lặp Parallel.For
để làm điều đó nhưng vòng lặp chạy một lần và lần thứ hai nó đưa ra lỗi trong khi nhận được phản hồi.Gửi nhiều WebRequest theo Parallel.For
Lỗi:
The operation has timed out
Code:
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();
});
Nó cung cấp cho bạn thông báo lỗi? Có thật không? Và có một số câu hỏi cụ thể mà bạn muốn hỏi không? –
Và lỗi là ...? – Icarus
Ngoại lệ là gì, nó xảy ra ở đâu? Bạn có chắc máy chủ không thực sự hết thời gian không? –