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
相关推荐
byte轻骑兵1 小时前
【PBAP】规范精讲[9]: 蓝牙PBAP的互联互通法则——GOEP互操作性要求深度解析路由侠内网穿透.1 小时前
本地部署开源 WSGI HTTP 服务器 Gunicorn 并实现外部访问箓维1 小时前
TCP Socket的基础实现SEO_juper2 小时前
Go 站点地图生成器:从首页爬全站,一键生成 sitemap.xml川石课堂软件测试10 小时前
学习软件测试需掌握的一些知识明天也要努力学习12 小时前
IP 协议的相关特性2501_9160074715 小时前
抓包工具功能对比,TraceEagle、Charles、Fiddler、Wireshark、mitmproxy 差别山雀~19 小时前
CSP 安全漏洞修复靠coding维持生计的potato19 小时前
从HTTP到存储——文件上传的底层原理梳理JSON_L20 小时前
TCP 粘包拆包解析及示例