Jersey REST客户端:如何将XML文件添加到POST请求的正文中?

Jersey REST客户端:如何将XML文件添加到POST请求的正文中?,第1张

Jersey REST客户端:如何将XML文件添加到POST请求的正文中

您始终可以在Java SE中使用java.net API:

URL url = new URL("http://localhost:8080/api/resource");HttpURLConnection connection = (HttpURLConnection) url.openConnection();connection.setDoOutput(true);connection.setInstanceFollowRedirects(false);connection.setRequestMethod("POST");connection.setRequestProperty("Content-Type", "application/xml");OutputStream os = connection.getOutputStream();TransformerFactory tf = TransformerFactory.newInstance();Transformer transformer = tf.newTransformer();FileReader fileReader = new FileReader("filename.xml");StreamSource source = new StreamSource(fileReader);StreamResult result = new StreamResult(os);transformer.transform(source, result);os.flush();connection.getResponseCode();connection.disconnect();


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5141175.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存