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
相关推荐
德迅云安全-上官9 小时前
源站隐身 + 流量清洗,高防 IP 品牌实力精选Ai拆代码的曹操16 小时前
TCP RST 包全链路定位:从 Connection Reset 错误到 Nginx keepalive_timeout 不匹配瓦学妹18 小时前
代理IP连接失败怎么办?2026代理IP异常排查与解决方法ITxiaobing202320 小时前
广告归因数据对齐实战:从IP溯源看点击欺诈与AppsFlyer P360的匹配度优化budaoweng060921 小时前
charles报错HTTP/1.1 200 Connection establishedTlSfoward21 小时前
爬虫指纹漂移监控与回归测试:JA3/JA4 变化为什么会影响线上验证 TLSFOWARDIPDEEP全球代理21 小时前
住宅IP、移动IP、机房IP有什么区别?CHANG_THE_WORLD1 天前
TCP 三次握手彻底解析:SYN、ACK、SEQ、确认号与状态迁移2501_915106321 天前
TraceEagle 代理抓包教程 本机和手机的 HTTPS 抓包方法小心我捶你啊2 天前
数据采集和Web解锁不是一回事,从用途到规则区分