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
相关推荐
JaneJiazhao2 分钟前
HTTPSOK:SSL/TLS证书自动续期工具JaneJiazhao3 分钟前
HTTPSOK:智能SSL证书管理的新选择CXDNW3 分钟前
【网络面试篇】HTTP(2)(笔记)——http、https、http1.1、http2.0城南vision2 小时前
计算机网络——HTTP篇。。。3 小时前
使用Rust实现http/https正向代理点点滴滴的记录13 小时前
RPC核心实现原理程思扬14 小时前
为什么Uptime+Kuma本地部署与远程使用是网站监控新选择?海绵波波10715 小时前
Webserver(4.8)UDP、广播、组播很透彻18 小时前
【网络】传输层协议TCP(下)蝌蚪代理ip19 小时前
辩论赛——动态IP与静态IP的巅峰对决