How to Decode a xml Sent over Url in java



I am firing a online xml in java to the method below:



public String WriteToServer(String xml) {
StringBuilder answer = new StringBuilder();
try {


String myurl="example.com";
//
URL url = new URL(myurl);

URLConnection conn = url.openConnection(Proxy.NO_PROXY);



conn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());

writer.write(xml);
writer.flush();

BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
answer.append(line);
}
writer.close();
reader.close();

} catch (Exception e) {
System.out.println(e);
}
return answer.toString();
}


My Problem is that the server receives a encoded xml so it cant understand and returns a 500 response to the client. How can I decode the xml to a plain text that the server can read?


No comments:

Post a Comment