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
相关推荐
汤愈韬8 小时前
NAT Server 与目的Nat7ACE9 小时前
Wireshark TS | TLP 超时时间凯瑟琳.奥古斯特14 小时前
NAT原理及作用详解W.A委员会16 小时前
DNS详解_Evan_Yao17 小时前
从 IP 路由到 Agent 路由:最长前缀匹配如何帮你分发任务?数据法师1 天前
开源情报收集工具GhostTrack深度测评:IP、手机号、用户名的合规信息查询方案想成为优秀工程师的爸爸1 天前
第三十篇技术笔记:郭大侠学UDS - 人有生老三千疾,望闻问切良方医灰子学技术1 天前
Envoy HTTP Connection Manager (HCM) 技术文档日取其半万世不竭2 天前
WordPress建站 + 免费SSL证书配置完整教程七七powerful2 天前
AI+运维提效--HTTPS 证书有效期监控方案