The HttpRequest object
(Microsoft.XMLHTTP) can be used by a client to send an arbitrary HTTP
request, receive the response, and have that response parsed by the
Microsoft XML Document Object Model. This object is integrated with
MSXML to support sending the request body directly from, and parsing
the response directly into, the MSXML DOM objects. Combined with the
support for XSL, this component provides an easy way to send structured
queries to HTTP servers, and display the results using a variety of
presentation.
The usual sequence is to call
the open method, set
any custom header information using setRequestHeader, and the send with the send method. The
response can be checked using one of the four response
properties.
JavaScript:
function PostOrder (xmldoc)
{
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
xmlhttp.Open("POST", "http://guruserver/processorder.asp", false);
xmlhttp.Send(xmldoc);
return xmlhttp.responseXML;
}
Server-Side JavaScript:
<%
Response.Expires=-1000;
var doc = Server.CreateObject("Microsoft.XMLDOM");
doc.load(Request);
// process and build resulting document
var result=Server.CreateObject("Microsoft.XMLDOM")
Response.ContentType="text/xml";
result.save(Response);
%>
In this example an XMLDOM document containing order information is posted to an ASP page which returns the result as a new XML document. The ASP page then loads the posted XML document, processes it, and builds an XML document from the results.
Syntax: object.onreadystatechange
This property is write-only, and specifies the event handler for the onreadystatechange event.
Syntax: httpRequest.readyState
This property represents the state of the request.
Syntax: httpRequest.responseBody
This property represents the response entity body as an array of unsigned bytes.
Syntax: httpRequest.responseStream
This property represents the response entity body as an IStream.
Syntax: httpRequest.responseText
This property represents the response entity body as a string.
Syntax: httpRequest.responseXML
This property represents the response entity body as parsed by the MSXML XMLDOM parser.
Syntax: object.status
This property is read-only and represents the HTTP status code returned by a request. It is only valid after the send method returns successfully.
Syntax: object.statusText
This property is read-only and represents the HTTP response line status as a BSTR value. It is only valid after the send method returns successfully.
Syntax: object.abort()
This method aborts the current HTTP request. The object will be returned to the UNINITIALIZED state, and the
Syntax: object.getAllResponseHeaders()
This method retrieves the values of all the HTTP headers as a string. Each name/value pair is separated by a combination carriage return/linefeed character. The results of this method are only valid after the send method returns successfully.
Syntax: object.getResponseHeader(bstrHeader)
This method retrieves the value of the specified HTTP header as a string from the response body. The results of this method are only valid after the method returns successfully. The full list of header variables that can be queried can be discovered with the getAllResponseHeaders method. Method This method initializes a Microsoft.XMLHTTP request, and specifies the method, URL and authentication information for the request. Password) Method This method sends an HTTP request to the server and receives a response.
Syntax: httpRequest.open(Method, URL, Async, User, Password)
This method initializes a Microsoft.XMLHTTP request, and specifies the method, URL and authentication information for the request.
Syntax: httpRequest.send(varHeader)
This method sends an HTTP request to the server and receives a response.
Syntax: object.setRequestHeader(bstrHeader, bstrValue)
This method specifies the name of an HTTP header.