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
相关推荐
Moyu_Friday12 小时前
网络安全基础-计算机网络应用与协议徐同保1 天前
免费ssl证书全流程AI配置(含七牛云cdn)幻智星科技1 天前
一个开源的纯FPGA网口采集卡flash俊杰1 天前
给工具调用划安全红线:SSRF 防护、逐跳复检与沙箱取舍anew___1 天前
《从零手写操作系统 (48):网络协议栈基础——Socket API与TCP/IP分层架构》TMT星球1 天前
2026阅文创作大会:首批AI精品动画亮相,推出OPC一站式平台与IP委员会模式泡海椒1 天前
从 XML 到 Excel:JQuick-Excel 代理与解析器如何协作程序员夏洛1 天前
TCP 和 UDP 有什么区别?