我需要在 java 中发送 xml 请求并捕获响应。
我怎样才能做到这一点 ?
我在谷歌中搜索,但到目前为止还没有任何可靠的信息。
此致,
瓦尔特·恩里克.
如果您想要执行 HTTP POST,那么您可以使用java.net.*Java SE 中的 API:
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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)