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
相关推荐
霜落长河10 小时前
抛弃TCP改用UDP,HTTP3怎么了?程序员mine1 天前
HTTPS-TLS加密与证书完全指南(中)之歆1 天前
现代 HTTP 客户端深度解析:Fetch 与 Axios酉鬼女又兒1 天前
零基础入门计算机网络运输层:端到端通信核心作用、端口号分类规则、复用分用工作机制及UDP与TCP协议全方位对比详解dog2501 天前
不要再继续优化 TCP程序员mine1 天前
HTTPS-TLS加密与证书完全指南(上)tianyuanwo1 天前
深入解析 RISC-V 虚拟化中的 UEFI 固件配置:从 XML 到 NVRAM 的生命周期管理VidDown2 天前
视频帧率技术详解:从 24fps 到 120fps,帧率如何影响你的观看体验?程序员mine2 天前
HTTPS-TLS加密与证书完全指南(下)hbugs0012 天前
EVE-NG V7常用网络协议流量洞察Filter