日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse()

發布時間:2024/9/20 asp.net 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse() 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

System.Net.WebException: The operation has timed out? at System.Net.HttpWebRequest.GetResponse()

在請求獲取響應結果的時候,超時,具體原因可能就是如下面Jon Skeet所說,

WebResponse implements IDisposable,
so you should use a using statement for it (and for the StreamReader you create from the stream).
If you leave a WebResponse open, it will take up a connection from the connection pool to that host,
and you can end up with timeouts this way.
WebResponse繼承IDisposable接口,會釋放非托管資源
所以你需要使用聲明來創建資源對象
如果你打開WebResponse資源響應,那么他將通過連接池連接主機,使用這個方式,超時將不會成為問題。
應該是這么翻譯吧╮(╯_╰)╭

This will close the stream and the response even if an exception is thrown,
so you'll always clean up the resources (in this case releasing the connection back to the pool) promptly.
這個將會關閉stream和response,即使出現拋出異常的情況
所以你總能夠即時清理好資源(釋放應用池的連接)

這個方式,嘗試了一下,暫時沒出現什么問題,算解決了99%吧,等到以后再出現什么問題,再來看。

下面是網上找到的一個解決方案:

http://stackoverflow.com/questions/15493321/system-net-webexception-the-operation-has-timed-out-on-httpwebresponse

Author:Jon Skeet

System.Net.WebException: The operation has timed out on HttpWebResponse

This may well be the problem:HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();WebResponse implements IDisposable, so you should use a using statement for it (and for the StreamReader you create from the stream). If you leave a WebResponse open, it will take up a connection from the connection pool to that host, and you can end up with timeouts this way. The fixed code would look like this:string responseString; using (var response = myReq.GetResponse()) {using (var reader = new StreamReader(response.GetResponseStream()){responseString = reader.ReadToEnd();} }This will close the stream and the response even if an exception is thrown, so you'll always clean up the resources (in this case releasing the connection back to the pool) promptly.

?

總結

以上是生活随笔為你收集整理的System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse()的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。