[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: 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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|