How to read XML returned by HTTP POST request?

Taimur

New Member
NOT a duplicate of my other question.I am sending a \[code\]POST\[/code\] request like this:\[code\] String urlParameters = "a=b&c=d"; String request = "http://www.example.com/"; URL url = new URL(request); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("charset", "utf-8"); connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length)); connection.setUseCaches(false); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); connection.disconnect();\[/code\]How can I read the xml response returned from a HTTP \[code\]POST\[/code\] request? Particularly, I want to save the response file as a .xml file, and then read it. For my usual \[code\]GET\[/code\] requests, I use this:\[code\] SAXBuilder builder = new SAXBuilder(); URL website = new URL(urlToParse); ReadableByteChannel rbc = Channels.newChannel(website.openStream()); FileOutputStream fos = new FileOutputStream("request.xml"); fos.getChannel().transferFrom(rbc, 0, 1 << 24); fos.close(); // Do the work\[/code\]
 
Top