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
相关推荐
幽兰的天空1 小时前
介绍 HTTP 请求如何实现跨域lisenustc1 小时前
HTTP post请求工具类心平气和️1 小时前
HTTP 配置与应用(不同网段)心平气和️1 小时前
HTTP 配置与应用(局域网)喜-喜1 小时前
C# HTTP/HTTPS 请求测试小工具Gworg2 小时前
网站HTTP改成HTTPS北顾南栀倾寒3 小时前
[Qt]系统相关-网络编程-TCP、UDP、HTTP协议7ACE3 小时前
Wireshark TS | 虚假的 TCP Spurious Retransmission大丈夫立于天地间4 小时前
ISIS基础知识湫qiu7 小时前
带你写HTTP/2, 实现HTTP/2的编码