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
相关推荐
mont evergreen7 小时前
青云宗秘录:libp2p 双节点聊天阵法源码卷FlightYe17 小时前
音视频修炼之容器与协议(七):HTTP-MP4 / HTTP-FLV用户849137175471619 小时前
抄来的 SNMP4J 代码能跑,却把"没回执"记成了"值为 0"——一次 GET 到底该怎么采对?知识汲取者1 天前
HTTP、SSE、WebSocket:三个老技术的区别、场景与选型ShineWinsu1 天前
对于Qt:TCP的解析郝学胜-神的一滴1 天前
Effective Python 条款45:巧用属性注解平滑升级类属性SEO_juper1 天前
HTTPS 混合内容检查工具:页面全站 https 了,但还有 http 资源在拖后腿进击的荆棘1 天前
Linux网络——应用层协议HTTP步峰代理-盾山1 天前
R语言爬虫实战:使用httr与XML解析网页数据并进行统计分析王亚博_Abel2 天前
域名是怎么变成 IP 的?手拆 DNS 解析四个实验实测