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
相关推荐
凌云C11 小时前
5G 协议体系与交互流程X7x516 小时前
跨厂商路由引入(重发布)实战指南:华为、华三、思科的逻辑差异与配置避坑猫头_17 小时前
AI 流式传输工程指南:有了 EventSource 为何还要 Fetch?玩转4G物联网17 小时前
FS800DTU 新品上线|免费使用 DMP 设备管理平台,支持远程批量配置 & OTA 升级Chloeis Syntax17 小时前
JAVAEE初阶 --- 构造HTTP请求风起洛阳@不良使18 小时前
spring中xml和注解开发的对比wuqingshun31415918 小时前
说说TCP的3次握手?为什么需要三次握手?无锡耐特森19 小时前
解决网关数据异常EtherNetIP 转Modbus TCP专用动态监测2401_8734794020 小时前
爬虫IP怎么防?IP离线库四层识别+日志留存,反爬留证两不误超级赛博搬砖工21 小时前
什么是移动代理IP?与住宅IP有何区别?