I receive three errors using the following function:
Private Sub readWebpage(ByVal url As String)
Try
Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(url)
Dim resp As System.Net.WebResponse = req.GetResponse
If Not resp.ContentType.Contains("text/html") And Not resp.ContentType.Contains("application/xhtml+xml") Then Exit Sub
Using Str As System.IO.Stream = resp.GetResponseStream
Using srRead As System.IO.StreamReader = New System.IO.StreamReader(Str)
parseHtml(srRead.ReadToEnd, url)
End Using
End Using
Catch ex As Exception
Debug.Print(ex.Message)
Debug.Print(url)
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unable to download content from: " & url)
End Try
End Sub
The remote server returned an error: (500) Internal Server Error.
Th开发者_C百科e server committed a protocol violation. Section=ResponseStatusLine
The remote name could not be resolved: 'dmoz.orgsearch'
How would I be able to prevent these errors?
You can't prevent remote errors. The best you can achieve is catch the exceptions the way you already are.
I would however suggest that you are using an incorrect url - dmoz.orgsearch
does not exist.
Was this supposed to be: http://www.dmoz.org/search?q=myquery
?
If the URL you are using is malformed, there isn't much you can do about it.
精彩评论