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
相关推荐
apihz2 小时前
批量获取3位未注册短域名免费API接口每日更新北京耐用通信2 小时前
传感器“断联”拖垮产线?耐达讯自动化网关让Ethernet IP转CCLink秒通!Maryfang132918915513 小时前
RTL8306MB的国产P2P替代方案用JL5106C的可行性分析编程修仙4 小时前
第五章 Spring XML配置原理白菜__4 小时前
去哪儿小程序逆向分析(酒店)2201_757830874 小时前
UDP协议2501_938810115 小时前
比特浏览器适用的IP类型超级大只老咪5 小时前
常用 HTTP 状态码汇总Zabbix_China5 小时前
零配置方案:Zabbix + HTTP 代理实现内网穿透工具的自动化管理苏打水com5 小时前
浏览器与HTTP核心考点全解析(字节高频)