public static void httpPost(String url, String xml) throws Exception {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/xml");
connection.setRequestProperty("Content-Length", String.valueOf(xml.length()));
connection.setDoOutput(true);
OutputStream outputStream = connection.getOutputStream();
outputStream.write(xml.getBytes());
outputStream.flush();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream inputStream = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line;
StringBuilder response = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
response.append(line);
}
bufferedReader.close();
System.out.println("请求成功: " + response.toString());
} else {
System.out.println("请求失败,响应头:" + connection.getHeaderFields());
System.out.println("请求失败,响应码:" + connection.getResponseCode());
}
}
Http请求Body中携带raw XML形式
demodashi6662024-08-29 19:18
相关推荐
code_li16 小时前
HTTPS免费证书配置指南untE EADO17 小时前
Tomcat的server.xml配置详解以太浮标18 小时前
华为eNSP模拟器综合实验之- 主机没有配置缺省网关时,通过路由式Proxy ARP实现通信(arp-proxy enable)时空自由民.18 小时前
蓝牙协议栈知识和网络协议栈知识对比醉颜凉19 小时前
网络协议基础必学:ARP 和 RARP 是什么?有什么区别?原理+流程图+对比详解杜子不疼.19 小时前
无需公网 IP!Grafana+内网穿透轻松实现数据看板远程访问tie123419 小时前
HTTP相关运维老郭19 小时前
TCP/IP协议栈排坑指南:3个高频连接故障与tcpdump精准定位zuowei288920 小时前
spring实例化对象的几种方式(使用XML配置文件)埃伊蟹黄面21 小时前
应用层HTTP协议