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 小时前
深入理解 TCP 协议:从三次握手到可靠传输Zelman11 小时前
HTTPS 协议JVM高并发14 小时前
使用 Cloudflare Tunnel(本地管理隧道)搭配 DigitalPlat 免费域名实现内网穿透吴声子夜歌14 小时前
Nginx应用与运维——Nginx HTTP模块详解(动态赋值功能模块)Zelman15 小时前
网络协议性能调优手册Zelman15 小时前
TCP-IP 协议栈设计哲学阿钱真强道15 小时前
28 嵌入式操作系统 | 网关加 TCP 命令通道:粘包/半包怎么切hasty16 小时前
一次 WebSocket 握手为何能终止进程?Undici CVE-2026-19534 的异常边界hasty17 小时前
前缀相同不代表同一网络:ip-address 跨地址族比较缺陷傲世仙尊20 小时前
HTTP请求与应答-URL全网唯一文件路径报文结构与短连接