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
相关推荐
TechWayfarer9 小时前
知乎/微博的IP属地显示为什么偶尔错误?用IP归属地查询平台自检工具3步验证孙同学_15 小时前
【项目篇】高并发服务器 - HTTP服务器组件拆解,从Util到HttpServerSilentSamsara16 小时前
HTTP/1.1 到 HTTP/3:每代协议解决了什么问题Flash.kkl17 小时前
传输层UDP、TCPzmj32032418 小时前
TCP/IP协议和以太网关系chao18984420 小时前
Socket-TCP 简易端口开放检测工具不会写DN20 小时前
TCP 长连接服务:登录注册认证体系实战指南一只小鱼儿吖21 小时前
基于OpenClaw的代理IP池自动化监控方案蕤葳-1 天前
理性分析:如何利用考证作为抓手,构建系统化知识体系与职业规划?通信小呆呆1 天前
各具神通——Vivado中不同系列的IP核差异详解