This discussion is archived
0 Replies Latest reply: Sep 22, 2006 2:27 PM by 807569 RSS

UrlEncode a stream or a Document

807569 Newbie
Currently Being Moderated
Hi,

I am trying to POST an xml document as form data. So, I build a org.w3c.dom.Document and want to post it. The problem is that I have to send it as
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
Now, I could of course convert the Document to a String and then use URLEncoder.encode but I would rather just URLEncode a Stream if this is somehow possible.
TransformerFactory tf =  TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");     
transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml");
transformer.transform(new DOMSource(doc), new StreamResult(out));
where out is:
URLConnection conn = null;
...
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setDoOutput(true);
conn.setDoInput(true);
...
OutputStream out = conn.getOutputStream();
So, is there a way to URLEncode a whole XML Document (doc) or a Stream (out)?

thanks,

dometz