[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Newbie question - passing XML using POST

  • From: Michael Brennan <Michael_Brennan@A...>
  • To: 'Stephen Young' <steve@n...>, xml-dev@l...
  • Date: Tue, 20 Mar 2001 18:22:31 -0800

xml post
The Microsoft.XMLHTTP is probably what you want. It provides high level
routines to make it pretty simple to send a DOM document and get a DOM
document back as the response, or you can send text or bytes.

Note that there is one bug in its implementation (which is unfortunately
shared by many other similar toolkits). When sending XML in this manner, the
XML is included in a MIME message. Many XML messaging toolkits are not
handling embedding XML in MIME in an appropriate fashion. I have tried to
submit a bug report to Microsoft on this, but have so far been unsuccessful
(and the attempt has proved to be a rather frustrating experience).

The bug can cause problems when trying to send non-ASCII text to some XML
messaging systems (e.g. if you are trying to send multi-lingual text). If
confining messages to ASCII text, the bug does not result in any problems.
There is a simple workaround. Here's the workaround (this sample code is
JScript, but VB or VBScript would look similar):

  var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  var url = ...                    (set the URL here)
  xmlhttp.open("POST", url, false);
  
  var xmldoc = new ActiveXObject( "Msxml.DOMDocument" );
  //... create or load the XML into the xmldoc object here

  // bug workaround -- we set the content-type header and add charset
parameter
  // to inform the receiver of the character encoding used. XMLHTTP object
  // does not properly do this on its own
  xmlhttp.setRequestHeader( "Content-Type", "text/xml; charset=utf-8" );

  // bug workaround -- if we send the DOM document itself, the XMLHTTP
  // object resets the content-type header to its default. To avoid this
  // we get the text of the XML from the DOM via the "xml" property. We
  // then send this text.
  xmlhttp.send( xmldoc.xml );
  xmldoc = xmlhttp.responseXML;  // xmldoc now contains the XML response
from the server

You could also check out the other XML messaging toolkits mentioned.
However, if you evaluate a toolkit, make sure it properly identifies the
character encoding in the content-type header as I show above. Many (if not
most) XML messaging toolkits simply use "text/xml" for the Content-Type
header. This is wrong. The result of this is that internationalized text can
end up being garbled on the receiving end. Follow the code sample above, and
you can avoid the problem (unless the receiving end is flawed).


> -----Original Message-----
> From: Stephen Young [mailto:steve@n...]
> Sent: Monday, March 19, 2001 5:39 PM
> To: xml-dev@l...
> Subject: Newbie question - passing XML using POST
> 
> 
> 
> Hi Guys
> 
> I'm trying find a way to send and receive XML using HTTP 
> POST.  You'd think
> it would be simple, but my low level programming skills are 
> struggling with
> the task.
> 
> I work in a Microsoft environment, and I have two methods 
> that work, but
> they both involve sending the XML as an array (Safe Array) of 
> bytes.  One
> sends an MSXML3 DOMDocument and the other does a unicode 
> converion of the
> bytes at each end.
> 
> 1) I don't imagine that either method will make it easy for 
> non-Microsoft
> apps to communicate and
> 2) There's gotta be an easier way - I'm just having a mental 
> block on what
> it is ;-)
> 
> A simple solution is to forget using POST altogether, and 
> either do the GET
> double round trip thing, or pass the XML in a querystring.  
> There has to be
> a better way.
> 
> I've taken a look at a few objects for the purpose (eg. MS 
> SOAP stuff) but I
> don't want to limit communication methods at this early 
> stage.  A simple
> method to initiate a transaction by sending an XML document is all I'm
> looking for.
> 
> Any ideas?
> 
> 
> ------------------------------------------------------------------
> The xml-dev list is sponsored by XML.org, an initiative of OASIS
> <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To unsubscribe from this elist send a message with the single word
> "unsubscribe" in the body to: xml-dev-request@l...
> 

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.