How To Identify HTTP Errors When You Use the ServerXMLHTTP Object (299566)



The information in this article applies to:

  • Microsoft XML 3.0
  • Microsoft XML 3.0 SP1
  • Microsoft XML 4.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0 SP3
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0 SP4
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0 SP5
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0

This article was previously published under Q299566

SUMMARY

When you use the Microsoft XML (MSXML) ServerXMLHTTP object to run an HTTP operation (such as POST, GET, and PUT) that is unsuccessful, a trappable run-time error is not raised. Instead, if a problem is encountered while trying to run an HTTP operation, Microsoft Internet Information Server (IIS) returns a response code and description that indicates an error.

To access the response code and description that IIS returns, examine the Status and StatusText properties of the ServerXMLHTTP object. In application code that uses the MSXML ServerXMLHTTP object to run HTTP operations, you must examine the value of its Status and StatusText properties to determine whether the operation was successful.

MORE INFORMATION

Step-by-Step Example

  1. Create a new Standard EXE project in Visual Basic 6.0. Form1 is created by default.
  2. On the File menu, click References, and select the Microsoft XML 3.0 or Microsoft XML 4.0 option.
  3. Add a CommandButton control to Form1.
  4. Paste the following code in the Click event procedure of the command button:
    'Use the version dependent PROGID of the ServerXMLHttp 'object if referencing MSXML 4.0.
    '( MSXML2.ServerXMLHTTP40 )
    Dim obj As MSXML2.ServerXMLHTTP
    Set obj = New MSXML2.ServerXMLHTTP
    obj.open "GET", "http://localhost/testerr.htm"
    obj.send
    
    If obj.Status >= 400 And obj.Status <= 599 Then
      Debug.Print "Error Occurred : " & obj.Status & " - " & obj.statusText
    Else
      Debug.Print obj.ResponseText
    End If
    					
  5. Change the URL parameter of the obj.Open statement to specify a path to a non-existent HTML file in one of your Web sites or IIS virtual directories. (It is assumed that you will have Read access to the specified Web site or virtual directory.)
  6. Save and run the Visual Basic project.
  7. Click the command button when the form is displayed to run an HTTP GET operation that accesses the specified, non-existent HTML file. The ServerXMLHTTP error handling code that follows the obj.send statement returns the "404 - Object not found" error message in the Visual Basic Immediate window.

    The error handling code in the above sample has been written to handle errors in the 400 and 500 IIS Response code series:
    • The 400 IIS Response code series (for example, "400 - Bad Request," "403 - Access Forbidden," and "404 - Object Not Found") indicates that the error occurs because of an invalid client request.
    • The 500 IIS Response code series (for example, "500 - Internal Server Error," "501 - Not Implemented," and "502 - Bad Gateway") indicates that the error occurs while the server is processing a client request.
    • The 200 Response code series indicates a successful operation.
  8. Stop running the Visual Basic project, and modify the URL parameter in the obj.Open statement to point to an existing HTML file in one of your Web sites or virtual directories.
  9. Run the project again, and click command button on the displayed form to run an HTTP GET operation that accesses the existing HTML file. If you have the required Read permission to access the specified HTML file, the Debug.Print obj.ResponseText statement writes out the contents of the HTML file to the Visual Basic Immediate window.

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

290761 Frequently Asked Questions about ServerXMLHTTP

289481 How To Proxy Configuration Must Be Run for ServerXMLHTTP to Work


Modification Type:MinorLast Reviewed:7/1/2004
Keywords:kbhowto KB299566