Sending XML Documents over HTTP
Learn about a neat little object called XMLHTTPRequest.
May 14, 2001
Recently, I wrote an application that passes an XML document to Microsoft BizTalk for processing. BizTalk can use several methods to accept an XML document. For my application, I send the XML document to an Active Server Pages (ASP) page that then places the document on the BizTalk message queue. How do I send the XML document over HTTP? I use a neat little object called XMLHTTPRequest.
With XMLHTTPRequest, you can issue a generic HTTP request to a Web server and use XML to send and receive data—and I don't just mean simple XML strings. In fact, with XMLHTTPRequest, you can send the entire XML Document Object Model (XMLDOM) as-is, in the Request object itself, to the server page.
Let's look at a quick example. The following VBScript snippet sends the XMLDOM to the BizTalk receive.asp page:
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")xmlhttp.open "POST" ,"http://ik/BizTalk/receive.asp",Falsexmltext = "YooHoo"Set xmldom = CreateObject("Microsoft.XMLDOM")xmldom.loadXML xmltextxmlhttp.send xmldom
The Open command takes five parameters:
Method—the HTTP method that opens the connection (e.g., POST, GET, PUT)
URL—an address to send the XMLDOM to; this must be an absolute URL
Optional indicator—whether the call is asynchronous or synchronous; true for asynchronous, false for synchronous
Optional User—for authentication; if this parameter is missing and the site requires authentication, the component displays a logon window
Optional Password—for authentication
Two useful XMLHTTPRequest properties are the status and responseText properties. The status property returns the HTTP status from the page to which you send the XMLDOM, and the responseText property gives you a textual representation of the response from the page. You can use these values to ensure that the page receives the XMLDOM.
On the server, you have the following VBScript snippet:
'get xml file set xmldoc = Server.CreateObject("Microsoft.XMLDOM")xmldoc.load(Request)
As you can see, you simply load the Request object directly into the XMLDOM and process the XML document. To use this object, you need Internet Explorer (IE) 5.0 or later and Microsoft XML Parser (MSXML) 2.0 or later.
For more information about the XMLHTTPRequest object, see the Microsoft Developer Network (MSDN) Web site. You should also read Dino Esposito's very good article, "Exchanging Data Over the Internet Using XML".
About the Author
You May Also Like