Note that there are some explanatory texts on larger screens.

plurals
  1. POhandlin Net.WebResponse with select statment in vb.net
    primarykey
    data
    text
    <p>i've the following function which gets html or xml source from some page, when there is 403 exception i found out the code doesn't continue to the select statement </p> <pre><code> 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 ' Setup our Web request objRequest = Net.WebRequest.Create(URL) objRequest.Timeout = TimeoutSeconds * 5000 ' Retrieve data from request Try objResponse = objRequest.GetResponse 'some times it gives an error server unavailable 503 Select Case CType(objResponse, Net.HttpWebResponse).StatusCode Case Net.HttpStatusCode.RequestTimeout Return "BadRequest" Case 403 Return "BadRequest" Case Net.HttpStatusCode.GatewayTimeout Return "BadRequest" Case Net.HttpStatusCode.InternalServerError Return "BadRequest" Case Net.HttpStatusCode.BadRequest Return "BadRequest" Case Net.HttpStatusCode.OK 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 Case Else MsgBox("Case Else") End Select catch Return "" End Try End Function </code></pre> <p>so how can i fix this? the debugger shows the exception in this line </p> <pre><code>objResponse = objRequest.GetResponse 'some times it gives an error server unavailable 503 or 403 </code></pre> <p>so it doesnt go to the select statment</p> <p>also second try with the same problem, it doesnt catch the error and doesnt show the exception message <img src="https://i.stack.imgur.com/yumQe.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload