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

RE: Transfering XML Documents Using HTTP Post - Objects vs text <or>my e

  • From: Michael Brennan <Michael_Brennan@A...>
  • To: 'Jerry Murray' <Jmurray@I...>, xml-dev@l...
  • Date: Wed, 03 Jan 2001 12:53:42 -0800

post xml java
> From: Jerry Murray [mailto:Jmurray@I...]
> [...]
> I have an application where we need to accept XML documents 
> from one company
> (Microsoft based environment) our company (Unix / Java environment) to
> another company and then pass documents back the other way.  
> We have agreed
> that we will both have servers capable of accepting HTTP 
> Posts.  An issue
> has developed on whether the body of the request should 
> include a parameter name. 

Your approach is not the best approach.

As Evan Lenz wrote:
> My understanding is that parameters in the POST body are 
> part of the HTML spec,
> not the HTTP spec, and they're specifically for the
> application/x-form-url-encoded content type.

The relevant Java classes include parameter parsing support that is
explicitly geared toward the common case of HTML form posting. To post XML,
set the "Content-Type" to "text/xml; charset=\"utf-8\"". When sending the
XML, create your own OutputStreamWriter with appropriate encoding:

    String xmlText = ...
    HttpURLConnection c = ...
    c.setRequestMethod("POST");
    c.setRequestProperty("Content-Type", "text/xml; charset=\"utf-8\"");
    c.setDoOutput(true);
    OutputStreamWriter out = new OutputStreamWriter(c.getOutputStream(),
"UTF8");
    out.write(xmlText);
    out.close();	

Similarly, read in XML using an InputStreamReader intialized with the
appropriate encoding. The encoding is indicated by the "charset" parameter
in the Content-Type header. Note, though, that the encoding type specified
will be an IANA registered charset name, not necessarily the same name used
by Java. If you know that everyone will only be sending you UTF-8 encoded
XML (which is recommended), then it's pretty simple; just use "UTF8" as the
Java encoding name ("utf-8" will also work). If they send you "utf-16", use
"Unicode" as the Java encoding name. If they send you another encoding, you
may need to map that name to the appropriate Java encoding (consult the JDK
documentation for supported encoding types). Note that the IANA names are
case insensitive.

Make certain your partners are all doing the right thing in regards to
encoding, as well. This is easy with the Microsoft tools. Microsoft's
XMLHTTP object sends in UTF-8 by default. Likewise, their XMLDOMDocument
object will write in UTF-8 format by default when saving directly to an ASP
Response object.

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.