Question

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.

The 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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top