I have used the following java code to POST xml data to a remote url and get the response. Here, I am using an xml file as the input. What I need is to pass the xml as a string
To get your XML file contents as a String use (add catch-block for IOException)
StringBuilder bld = new StringBuilder();
FileReader fileReader = new FileReader(input);
BufferedReader reader = new BufferedReader(fileReader);
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
bld.append(line);
}
String xml = bld.toString();
The better way is to use Java Web Services JAX-WS or Java Restful Web Services JAX-RS.