1
我嘗試使用來自其他帖子的建議,並仍然沒有解決方案。發送POST請求時,有時會剛剛開始凍結並停止。我設置我的代碼如下,現在基本上,如果我不知道爲什麼它凍結,那麼它需要超時,處理異常並重新啓動函數。httpwebresponse = request.getresponse凍結
For i As Integer = 0 To searchItems.Count - 1
If uri.Scheme = uri.UriSchemeHttps Then
Dim request As HttpWebRequest = HttpWebRequest.Create(url)
request.Method = "POST"
request.ContentLength = data.Length
request.ContentType = "application/xml; charset=utf-8"
request.Timeout = 20000
Dim writer As New StreamWriter(request.GetRequestStream)
Dim postBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(data)
writer.Write(postBytes)
***Using oResponse As HttpWebResponse = request.GetResponse()*** ' this is where it freezes
Dim reader As New StreamReader(oResponse.GetResponseStream())
responseData = reader.ReadToEnd()
reader.Dispose()
oResponse.Close()
End Using
request.Abort()
writer.Close()
End If
End If
Next
Catch e As WebException
If e.Status = WebExceptionStatus.ProtocolError Then
....
有誰知道這是編碼錯誤還是別的嗎?
好想通了,爲什麼它的懸掛......我寫的請求,我得到的錯誤不能關閉流,因爲即使我設置了內容的長度其期待更多的字節
我在一個循環做這個,它似乎在第240個請求正常工作。 – vbNewbie 2010-12-13 04:32:24
它在循環中間的迭代中凍結了嗎?或者當它凍結時,它會在第一次迭代時發生並且永遠不會通過其餘的? – 2010-12-13 17:07:21
它在第一次迭代時凍結,並且不會繼續...但是在我發佈的數據不同之前,它經歷了所有沒有任何問題......可以是目標服務器對我發佈的數據有問題>我檢查了數據,但它確實符合 – vbNewbie 2010-12-13 17:14:13