Microsoft KB Archive/299566

From BetaArchive Wiki
Knowledge Base


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.

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



Additional query words: execute

Keywords: kbhowto KB299566