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
相关推荐
我不会插花弄玉18 小时前
5.应⽤层协议HTTP【由浅入深-网络】我不会插花弄玉1 天前
6.传输层协议UDP【由浅入深-网络】火云代理1 天前
更换网络后为什么会退出登录?分清 IP、Cookie 与会话的关系火云代理2 天前
同一个网站,有的网络能打开、有的打不开?认识 IPv4 与 IPv6 的访问差异坤坤子吖2 天前
Linux网络编程:TCP 粘包与半包问题,如何正确处理 TCP 流式数据?火云代理2 天前
Python 使用代理 IP 前,先弄清 Requests 的配置来源与验证方法如夏倾城2 天前
QUIC——HTTP/3 的唯一底层传输协议 及 0-RTT恢复略懂而已3 天前
安装SSL后网站速度变慢?Thanks_ks3 天前
HTTPS:浏览器地址栏那把锁的工作原理杨凯凡3 天前
Spring Boot 大文件下载如何实现断点续传?HTTP Range、206 与 416 实战