[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>mye
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. http://skew.org/xml/misc/xml_vs_http/#urlencoded 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@l... [mailto:xml-dev-errors@l...]On Behalf Of Jerry Murray Sent: Tuesday, January 02, 2001 8:08 PM To: xml-dev@l... 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 name. My understanding is that it is common to use parameters in the post body (even if it is just one value): an example from http://www.w3.org/MarkUp/html-spec/html-spec_8.html The user then conducts an HTTP POST transaction using the URI `http://www.w3.org/sample'. The message body would be (ignore the line break): name=John+Doe&gender=male&family=5&city=kent&city=miami& other=abc%0D%0Adef&nickname=J%26D 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 jmurray@i... 925-225-8746 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; in.close(); URL downeyjrURL = new URL("http://www.ourhost.com/servlet/INBOX"); HttpURLConnection c = (HttpURLConnection)(downeyjrURL.openConnection()); c.setDoOutput(true); PrintWriter out = new PrintWriter(c.getOutputStream()); // Here's whether the parameter is set. out.println("xmldoc=" + URLEncoder.encode(inputString)); out.close(); BufferedReader in2 = new BufferedReader(new InputStreamReader(c.getInputStream())); String inputLine; while((inputLine = in2.readLine()) != null) System.out.println(inputLine); in2.close(); } } 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 { response.setContentType("text/plain"); PrintWriter out = response.getWriter(); HttpSession session = request.getSession(); String xml = request.getParameter("xmldoc"); out.println(xml); String fileName = "input.xml"; PrintWriter fileWriter = new PrintWriter (new BufferedWriter(new FileWriter(fileName))); fileWriter.write(xml); fileWriter.flush(); fileWriter.close(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } }
|
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
|