i need to send a xml request in java and catch the response. How can i do this ?
I search in the google but nothing solid until now.
Best regards, Valter Henrique.
If you are looking to do an HTTP POST, then you could use the java.net.* APIs in Java SE:
try {
URL url = new URL(URI);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/xml");
OutputStream os = connection.getOutputStream();
// Write your XML to the OutputStream (JAXB is used in this example)
jaxbContext.createMarshaller().marshal(customer, os);
os.flush();
connection.getResponseCode();
connection.disconnect();
} catch(Exception e) {
throw new RuntimeException(e);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With