Microsoft KB Archive/299566

= How To Identify HTTP Errors When You Use the ServerXMLHTTP Object =

Article ID: 299566

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft XML Core Services 4.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 6.0 Enterprise Edition
 * 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

-



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.



Step-by-Step Example
 Create a new Standard EXE project in Visual Basic 6.0. Form1 is created by default. On the File menu, click References, and select the Microsoft XML 3.0 or Microsoft XML 4.0 option. Add a CommandButton control to Form1.  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 &quot;GET&quot;, &quot;http://localhost/testerr.htm&quot; obj.send

If obj.Status >= 400 And obj.Status <= 599 Then Debug.Print &quot;Error Occurred : &quot; & obj.Status & &quot; - &quot; & obj.statusText Else Debug.Print obj.ResponseText End If                    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.) Save and run the Visual Basic project. 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 &quot;404 - Object not found&quot; 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: <ul> The 400 IIS Response code series (for example, &quot;400 - Bad Request,&quot; &quot;403 - Access Forbidden,&quot; and &quot;404 - Object Not Found&quot;) indicates that the error occurs because of an invalid client request.</li> The 500 IIS Response code series (for example, &quot;500 - Internal Server Error,&quot; &quot;501 - Not Implemented,&quot; and &quot;502 - Bad Gateway&quot;) indicates that the error occurs while the server is processing a client request.</li> The 200 Response code series indicates a successful operation.</li></ul> </li> 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.</li> 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.</li></ol>

<div class="references_section">