How to detect Server or Networking failures when using XMLHTTP

Applies to: Internet Explorer 10Internet Explorer 9

Summary


When you use XMLHTTP requests to receive data from a webserver, the requests may be acknowledged by the server at the TCP-level, but then aborted by the server without delivering the HTTP response. In this scenario, the web application may need to handle this behavior in order to proceed by using a retry operation or other similar error handling.

This can be achieved by checking the variable status within the callback function onreadystatechange. For example, in a case where the XMLHTTP call is not successful this status will have the value 12152, which is equivalent to ERROR_HTTP_INVALID_SERVER_RESPONSE. The readystate itself is already set to 4 (READYSTATE_COMPLETE).

The sample for the onreadystatechange event documented in MSDN (see the More Information section below) checks for the status codes 200 (OK) or 304 (Not modified), and interprets these status codes as successful. Any other HTTP status code is considered to be an error condition, which will include the status 12152.

When using the HTTP POST method in the XMLHTTP request, be aware of the limitations that are described in the following Knowledge Base article:

When you use Internet Explorer or another program to perform a re-POST operation, only the header data is posted


Specifically, note that when a re-POST has been initiated only the HTTP-headers are sent, and the data which should have been POSTed is not sent again. Since the HTTP headers of the POST request will typically include a Content-Length header indicating the size of the POST data, the server will have to wait for the data until a timeout has been triggered, which will usually result in an HTTP 500 (Server error) response from the webserver.

When you enable the hotfix from KB895954 by creating the FeatureControl key FEATURE_SKIP_POST_RETRY_ON_INTERNETWRITEFILE_KB895954, the incomplete re-POST will not occur and the status 12152 will be reported as the status to the XMLHTTP object. Therefore you may consider performing a retry of the request through script.

More Information


895954 When you use Internet Explorer or another program to perform a re-POST operation, only the header data is posted
http://support.microsoft.com/kb/895954/EN-US

Description of the onreadystatechange event
http://msdn.microsoft.com/en-us/library/ie/dd576252(v=vs.85).aspx

193625 INFO: WinInet Error Codes (12001 through 12156)
http://support.microsoft.com/kb/193625