[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Transfering XML Documents Using HTTP Post - Objects vs text <or>my environment or yours
- From: Michael Brennan <Michael_Brennan@Allegis.com>
- To: 'Jerry Murray' <Jmurray@Ironplanet.com>, email@example.com
- Date: Wed, 03 Jan 2001 12:53:42 -0800
> From: Jerry Murray [mailto:Jmurray@Ironplanet.com]
> 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.setRequestProperty("Content-Type", "text/xml; charset=\"utf-8\"");
OutputStreamWriter out = new OutputStreamWriter(c.getOutputStream(),
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
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