我創建了一個WebRequest
以將一些HTML內容發佈到另一個Web服務器。當我使用正常的文本內容時,它可以正常工作,但是當我發佈HTML內容時,在調用GetResponse()
時出現超時錯誤。調用GetResponse()時超時異常
WebResponse response = request.GetResponse()
我怎樣才能找出問題? 我試着爲WebException
添加一個錯誤處理程序,但我無法捕捉到這個異常。
請求代碼:
byte[] byteArray = Encoding.UTF8.GetBytes(sPostData);
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create(httpUri);
// Set the 'Timeout' property in Milliseconds.
//request.Timeout = 20000;
// Set the ContentType property of the WebRequest.
request.ContentType = contentType;
// Set the Method property of the request to POST.
request.Method = postMethod;
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
using (Stream PostStream = request.GetRequestStream())
{
PostStream.Write(byteArray, 0, byteArray.Length);
}
// Get the response.
using (WebResponse response = request.GetResponse())
{
// Get the stream containing content returned by the server.
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(responseStream))
{
string responseFromServer = reader.ReadToEnd();
result = responseFromServer;
}
}
}
您是否也可以顯示請求代碼? – BrokenGlass 2011-04-20 01:34:06
請參閱請求代碼已添加到問題 – Roshe 2011-04-20 02:43:26
任何想法? – Roshe 2011-04-26 04:34:02