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: Transfering XML Documents Using HTTP Post - Objects vs text <or>myenvironment or yours

This link was recently posted to xml-dev.  You might find it helpful.  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 document below discourages
the use of it, because URL-encoding can only reliably work with ASCII,
whereas XML may consist of any Unicode characters.


Another thing to note is that the Java HttpURLConnection defaults to
application/x-form-url-encoded content type, and has a specific API for
getting and setting parameters for it.  This is kind of weird for something
advertising itself as an HTTP API (as opposed to an HTML browser emulator).
Thus, you may need to explicitly set the content type to text/xml.

Hope this helps,
Evan Lenz

-----Original Message-----
From: xml-dev-errors@lists.xml.org
[mailto:xml-dev-errors@lists.xml.org]On Behalf Of Jerry Murray
Sent: Tuesday, January 02, 2001 8:08 PM
To: xml-dev@lists.xml.org
Subject: Transfering XML Documents Using HTTP Post - Objects vs text
<or> myenvironment or yours

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

My understanding is that it is common to use parameters in the post body
(even if it is just one value):

         an example from
The user then conducts an HTTP POST transaction using the URI
`http://www.w3.org/sample'. The message body would be (ignore the line

I have include sample code for sending the post and code for receiving the
request.  Is this an unusual way of doing it?  If we don't use a parameter
name, then it seems that I will have to use request.getReader();     and
then get the text from the BufferedReader.

Any suggestions?

Thanks in advance,

Jerry Murray

Code for the Client

import java.net.*;
import java.io.*;
import java.net.HttpURLConnection.*;

public class testpost {

  public static void main(String[] args) throws Exception {
    String inputString = "";
    String input;
    BufferedReader in = new BufferedReader(new FileReader(arg[0]));
    while((input = in.readLine()) != null)
       inputString = inputString + input;

    URL downeyjrURL = new URL("http://www.ourhost.com/servlet/INBOX");
    HttpURLConnection c = (HttpURLConnection)(downeyjrURL.openConnection());
    PrintWriter out = new PrintWriter(c.getOutputStream());
    // Here's whether the parameter is set.
    out.println("xmldoc=" + URLEncoder.encode(inputString));

    BufferedReader in2 = new BufferedReader(new

    String inputLine;
    while((inputLine = in2.readLine()) != null)

Code for the server:

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class INBOX extends HttpServlet {

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
        PrintWriter out = response.getWriter();

        HttpSession session = request.getSession();

        String xml = request.getParameter("xmldoc");


	String fileName = "input.xml";
	PrintWriter fileWriter = new PrintWriter (new BufferedWriter(new

    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
        doGet(request, response);