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
相关推荐
阿米亚波4 小时前
【EVE-NG 实战】防火墙基础(VLAN · VRRP · NAT · ACL · 静态路由)tiantianuser4 小时前
NVME-oF IP 设计2 :设计之前的调研!用户125758524365 小时前
Go 里读取 request body 后,下游拿不到参数:别让日志中间件把请求吃掉2401_873479406 小时前
如何识别代理IP和伪装流量?用IP情报工具三步穿透住宅代理伪装STDD6 小时前
Traefik 中间件深度配置:限流、认证、IP 白名单与错误页面定制曾令胜7 小时前
HTTP协议基础总结sdghterhd17 小时前
WebSocket 快速入门教程(附示例源码)IpdataCloud1 天前
AI生成的Avalon恶意框架怎么防?用IP离线库识别模块化C2通信一口一口吃成大V1 天前
lattice mipi ip开启DESKEW_EN属性(“ENABLED“),输出异常斯特凡今天也很帅1 天前
xml页面可以打开,不报错,但是显示数据的地方也不显示,我是怎么解决的