Microsoft Knowledge Base Email Alertz

When you use the Microsoft XML (MSXML)

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 299566 - Last Review: October 19, 2009 - Revision: 4.0

How To Identify HTTP Errors When You Use the ServerXMLHTTP Object

This article was previously published under Q299566

On This Page

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 6.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 6.0.
    '( MSXML2.ServerXMLHTTP60 )
    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 more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
290761  (http://kbalertz.com/Feedback.aspx?kbNumber=290761/ ) Frequently Asked Questions about ServerXMLHTTP
289481  (http://kbalertz.com/Feedback.aspx?kbNumber=289481/ ) You may need to run the Proxycfg tool for ServerXMLHTTP to work

APPLIES TO
  • Microsoft XML Parser 3.0
  • Microsoft XML Parser 3.0 Service Pack 1
  • Microsoft XML Core Services 4.0
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 3
  • Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 4
  • Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 5
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft XML Core Services 6.0
Keywords: 
kbhowto KB299566
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate