VB.net 網路timeout 時錯誤~

2007-06-26 3:27 am
Dim httpReq As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create(URL), System.Net.HttpWebRequest)
httpReq.AllowAutoRedirect = False
httpReq.Timeout = 3000
'如果timeout 時....成個exe 出error...之後個vb 會highlight 左下面呢句野
Dim httpRes As System.Net.HttpWebResponse = CType(httpReq.GetResponse(), System.Net.HttpWebResponse)
'Highlight end here- -"
If httpRes.StatusCode = System.Net.HttpStatusCode.OK Then
....
..
.
我想問一下~我點可以設定佢timeout 果時會做D 咩?
更新1:

' highlight here 放high 左果句係果個位? 不過咁httpReq 會出未宣告~ 哈哈~小弟係自學中的新手...希望唔好見怪

回答 (1)

2007-06-26 8:07 am
✔ 最佳答案
Timeout是錯誤,因此只可以 Catch Timeout Exception

Try
' Your code here
Catch Ex As WebException
If Ex.Status = WebExceptionStatus.Timeout Then
' highlight here
End If
Catch Ex As Exception
' catch general exception
End Try


收錄日期: 2021-04-25 20:34:03
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070625000051KK03765

檢視 Wayback Machine 備份