Sending XML Documents over HTTP

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",False
xmltext = "<message>YooHoo</message>"
Set xmldom = CreateObject("Microsoft.XMLDOM")
xmldom.loadXML xmltext
xmlhttp.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".

Discuss this Article 1

Anonymous User (not verified)
on Oct 24, 2004
I thought this was useful.

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Mike Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
Vision road sign
May 6, 2013
blog

Cheaters Never Win, Even in TPC Benchmarks

In this portion of the series on database benchmarking, I want to tell you about one of my favorite aspects of the TPC benchmarks – CHEATING....More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.