0
나는 내 웹 사이트에서 HTML 소스를 얻기 위해 사용하는 다음 함수는vb.net는
Public Function GetPageHTML(ByVal URL As String, _
Optional ByVal TimeoutSeconds As Integer = 10) _
As String
' Retrieves the HTML from the specified URL,
' using a default timeout of 10 seconds
Dim objRequest As Net.WebRequest
Dim objResponse As Net.WebResponse
Dim objStreamReceive As System.IO.Stream
Dim objEncoding As System.Text.Encoding
Dim objStreamRead As System.IO.StreamReader
Try
' Setup our Web request
objRequest = Net.WebRequest.Create(URL)
objRequest.Timeout = TimeoutSeconds * 1000
' Retrieve data from request
Try
objResponse = objRequest.GetResponse 'some times it gives an error server unavailable 503
Catch ex As WebException
MsgBox(ex.Message)
End Try
objStreamReceive = objResponse.GetResponseStream
objEncoding = System.Text.Encoding.GetEncoding(_
"utf-8")
objStreamRead = New System.IO.StreamReader(_
objStreamReceive, objEncoding)
' Set function return value
GetPageHTML = objStreamRead.ReadToEnd()
' Check if available, then close response
If Not objResponse Is Nothing Then
objResponse.Close()
End If
Catch
' Error occured grabbing data, simply return nothing
Return ""
End Try
End Function
몇 배 objResponse 오류 "503 서버를 사용할 수없는 제공 한 "및 403과 같은 많은 다른 오류 등등 어떻게 각각의 오류를 독립적으로 처리 할 수 있습니까?
이 함수는 언젠가 요청을 다시 시도 할 수 있습니까? 문제가 try 문을이 처리하지 않는 것 및 왜 MsgBox 예외가 표시되지 않습니다 모르지만 디버거에서 오류를 보여줍니다.