Http请求Body中携带raw XML形式

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