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 分钟前
什么是 MCP(模型上下文协议)Ether IC Verifier2 小时前
TCP/IP四层协议详解与以太网包发送过程Summer不秃4 小时前
深入理解 Token 无感刷新:从并发雪崩到单例锁 + 请求队列的完整实现Ether IC Verifier5 小时前
CPU/GPU/NPU/DPU功能详解与AI应用分析lunzi_08268 小时前
《图解HTTP》--第3章 HTTP报文内的HTTP信息只可远观9 小时前
Android XML命令式和Jetpack Compose声明式UIShota Kishi10 小时前
ERPC 在 Solana RPC 中集成 Pyth Hermes 兼容的 Price API:从架构到调用的技术解析念越10 小时前
HTTPS 安全内核:对称与非对称加密的博弈,数字证书一战定局Jinkxs11 小时前
LoadBalancer- 核心术语详解:转发 / 监听 / 节点池 / 虚拟 IP 等必知概念运维行者_11 小时前
理解应用性能监控