OBJECT:  HttpRequest

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.

In the following example an XMLDOM document containing order information is posted to an ASP page which returns the result as a new XML document.

Code (JScript):
function PostOrder (xmldoc)
{
   var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
   xmlhttp.Open("POST", "http://guruserver/processorder.asp", false);
   xmlhttp.Send(xmldoc);
   return xmlhttp.responseXML;
}

The ASP page then loads the posted XML document, processes it, and builds an XML document from the results.

Code (Server-Side JScript):
<%
   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);
%>

denotes a Microsoft extension to the W3C DOM.

PROPERTIES

onreadystatechange Property
This property is write-only, and specifies the event handler for the onreadystatechange event.

Syntax: Document.onreadystatechange

readyState Property
This property represents the state of the request.

Syntax: HttpRequest.readyState

responseBody Property
This property represents the response entity body as an array of unsigned bytes.

Syntax: HttpRequest.responseBody

responseStream Property
This property represents the response entity body as an IStream.

Syntax: HttpRequest.responseStream

responseText Property
This property represents the response entity body as a string.

Syntax: HttpRequest.responseText

responseXML Property
This property represents the response entity body as parsed by the MSXML XMLDOM parser.

Syntax: HttpRequest.responseXML

status Property
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: HttpRequest.status

statusText Property
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: HttpRequest.statusText

METHODS

abort Method
This method aborts the current HTTP request. The object will be returned to the UNINITIALIZED state, and the open method must be called next.

Syntax: HttpRequest.abort( )

getAllResponseHeaders Method
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: HttpRequest.getAllResponseHeaders( )

getResponseHeader Method
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 send method returns successfully. The full list of header variables that can be queried can be discovered with the getAllResponseHeaders method.

Syntax: HttpRequest.getResponseHeader(bstrHeader)

open Method
This method initializes a Microsoft.XMLHTTP request, and specifies the method, URL and authentication information for the request.

Syntax: HttpRequest.open(Method, URL, Async, User, Password)

send Method
This method sends an HTTP request to the server and receives a response.

Syntax: HttpRequest.send(varHeader)

setRequestHeader Method
This method specifies the name of an HTTP header. The 'bstrHeader' parameter is a string that should be the actual text of the HTTP header without any colon. The 'bstrValue' parameter should be the string value of the header. If a header of the same name already exists, it is replaced.

Syntax: HttpRequest.setRequestHeader(bstrHeader, bstrValue)


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information