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
相关推荐
源图客21 分钟前
Minio配置HTTPS服务liulilittle3 小时前
bpftrace 跟踪 tcp_write_xmit (内核TCP写出提交)齐鲁大虾5 小时前
如何彻底解决从公网HTTP页面请求私有HTTP资源跨域问题g3voip6 小时前
洁净室IP电话机是什么?无尘车间语音通信设备的功能与部署要点上海云盾第一敬业销售6 小时前
网站安全防护策略与误报处理方案探索韩曙亮6 小时前
【Flutter】Flutter 中的 Android / iOS 特殊配置 ① ( 网络权限配置 | HTTP 明文传输配置 | 应用名称配置 )hashiqimiya7 小时前
每日android布局xml文件猫头虎8 小时前
猫头虎AI分享|樱桃键盘Ctrl键失效解决方案:FN+PAUSE 长按10秒恢复出厂设置保姆级教程network_tester9 小时前
SENT/PSI5传感器TSN集成测试:打通传统传感与未来车载网络的“最后一公里”WIZnet9 小时前
W55RP20-EVB-MKR 模块 MicroPython 实战 (11):HTTP 协议与 OneNET 平台数据上云