开发者

trap error in httpwebresponse

开发者 https://www.devze.com 2023-01-30 22:00 出处:网络
I have a httpwebrequest where a post data that goes into a freeze waiting for a response. I want to have this timeout so I can continue looping and ignore the error.

I have a httpwebrequest where a post data that goes into a freeze waiting for a response. I want to have this timeout so I can continue looping and ignore the error.

 request.Method = "POST"
                        request.ContentLength = data.Length
                        request.ContentType = "application/xml; charset=utf-8"
                        request.Timeout = 20000
 ....

 **Using oResponse As HttpWebResponse = request.GetResponse()**
                            Dim reader As New StreamReader(oResponse.GetResponseStream())
         开发者_开发百科                   responseData = reader.ReadToEnd()
                            reader.Dispose()
                            oResponse.Close()
                        End Using


Have a look at the HttpWebRequest.Timeout Property.

With this you can get or set the time-out value in milliseconds for the GetResponse and GetRequestStream methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消