Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8497729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:12:33+00:00 2026-06-11T00:12:33+00:00

in the following code i am trying to handle different server resposes: this function

  • 0

in the following code i am trying to handle different server resposes:
this function is used to read xml or html soruce from a web page
and in the commented line i get “Object reference not set to an instance of an object.”
i wonder why.

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

        Select Case CType(objResponse, Net.HttpWebResponse).StatusCode 'Here is where i get the error Object reference not set to an instance of an object.

    Case Net.HttpStatusCode.InternalServerError
        'This is sloppy, but a quick example for one of your sub-questions.
        System.Threading.Thread.Sleep(10000)
        'Try again.
        objResponse = objRequest.GetResponse
    Case Net.HttpStatusCode.BadRequest
        'Error Handling
    Case Net.HttpStatusCode.OK
        'Proceed as normal.
    Case Else
        'Error Handling

End Select

        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

now when i remove the switch statement and just write the objResponse as

objResponse = objRequest.GetResponse

except i get an exception of error 403 or 503, i don’t know how to handle this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:12:34+00:00Added an answer on June 11, 2026 at 12:12 am

    Your error line:

    Select Case CType(objResponse, Net.HttpWebResponse).StatusCode

    is called without ever assigning anything to objResponse.

    You need to change it to:

    objResponse = objRequest.GetResponse
    
    Select Case CType(objResponse, Net.HttpWebResponse).StatusCode`
    

    In regards to getting HTTP error codes for the page you are trying to ftech, here are the meanings of them and their causes:

    http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to handle an exception caused by this following code: begin reader
I'm trying the following code http://code.google.com/apis/ajax/playground/#change_the_playing_video It works well when runned from the playground
I am trying to convert the following code from Trefethen's Spectral Methods in MATLAB
I am trying to run the following code from within Eclipse: Process process =
I'm trying to use the following code to handle SSL connections in iOS. It
I get this solitary error while trying to compile the following code in code::blocks.
I am trying to handle socket in different threads creating runtime failure. See following
The following code is trying to remove any duplicate characters in a string. I'm
I am trying the following code in eclipse: public class A { List<Integer> intList
I am trying the following code to AutoComplete contact details as the user types

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.