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
相关推荐
测试员周周17 小时前
【skills5】一份 spec 生成 k6/JMeter/Locust:性能压测 + 全站截图,上线前的双保险潘潘的嵌入式日记18 小时前
改完Keil工程文件被缓存覆盖?——uvprojx编辑的进阶四坑酣大智18 小时前
常用 IP 协议号大全(IP 层承载的上层协议)Full Stack Developme1 天前
Flowable XML标签大全paopaokaka_luck1 天前
基于Springboot3+vue3的旅游景区点评系统(AI审核、webSocket聊天、协同过滤算法、Echarts图形化分析)熬夜苦读学习1 天前
基于websocket的多用户五子棋网页游戏广州灵眸科技有限公司1 天前
xfce桌面旋转说明:基于灵眸科技EASY-EAI-Nano-TBGlobalSign数字证书1 天前
ACME 的 HTTP 验证和 DNS 验证,哪种更适合自动续期?微硬创新1 天前
耐达讯自动化PROFINET转DeviceNet网关:医药包装生产线的合规与效率双保障米尔的可达鸭1 天前
深入操作系统 Socket 底层:EPOLLOUT 可写事件管理 + 非阻塞异步