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
相关推荐
liann1197 小时前
3.2_红队攻击框架--MITRE ATT&CKzjun10019 小时前
TCP专栏-1.TCP协议概念说明仍然.11 小时前
网络编程(二)---TCP字节流套接字编程Ether IC Verifier13 小时前
OSI网络七层协议详细介绍环流_14 小时前
HTTP 协议的基本格式AIwenIPgeolocation15 小时前
IP地址数据服务:赋能游戏行业体验优化与精细化运营TechWayfarer16 小时前
2026年IP归属地查询平台选型指南:金融风控、异地登录、离线库全场景实测不会编程的懒洋洋16 小时前
WPF XAML+布局+控件Rust研习社16 小时前
Rust + PostgreSQL 极简技术栈应用开发