OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Newbie question - passing XML using 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@neon.com.au]
> Sent: Monday, March 19, 2001 5:39 PM
> To: xml-dev@lists.xml.org
> 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@lists.xml.org
>