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
相关推荐
Shell运维手记2 小时前
ARP 协议超详细讲解(适合网工考试 / 运维理解)huainingning4 小时前
华三瘦AP切换为胖AP并配置无线功能减瓦6 小时前
告别Postman——用VSCode优雅地发起Http请求跨境技工小黎7 小时前
4G/5G 移动代理实战:什么时候必须用移动 IP?wechatbot8887 小时前
解决企业微信官方 API 短板:iPad 协议全功能对接方案米尔的可达鸭8 小时前
UDP 通信深度实验:从 Windows FastPath 到 ICMP 端口不可达的完整排查Dxy12393102168 小时前
Python 实现POST上行压缩上传可用HTTP库汇总午安~婉8 小时前
git中http与ssh连接Full Stack Developme9 小时前
Tomcat 如何处理HTTP请求味悲10 小时前
Apache HTTP 服务器配置