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
相关推荐
爱研究的小梁31 分钟前
打破时延‑带宽悖论|乾元通 QMP‑UDP,为无人载具提供低延时高带宽原生通信方案xie0510_36 分钟前
TCP socket恋恋西风1 小时前
TCP 三次握手 / 四次挥手 讲解00后程序员张1 小时前
Android证书绑定抓包失败?Android SSL Pinning绕过实战指南比兔代理2 小时前
动态 IP 代理深度讲解:IP 地址轮换机制与会话保持方案一直C2 小时前
Linux应用软件编程|TCP协议与Socket全套编程(三次握手、四次挥手、报文头部、核心机制)隔窗听雨眠3 小时前
大模型实时通信协议深度对比:SSE、WebSocket与gRPC的选型指南与实战解析风萧萧19994 小时前
JAVA :JSONObject转换为XML唐古乌梁海4 小时前
传输协议https-TCPliulilittle5 小时前
REALITY 代理隧道的有效检测方法: 被动、主动与确定性三层实证研究