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
相关推荐
码匠许师傅7 小时前
【C++三方组件】cpp-httplib:一个头文件起 HTTP 服务不会就选b7 小时前
Linux之应用层协议HTTP(二)hasty7 小时前
只监听本机为何仍需鉴权?Cline Hub 的 WebSocket 信任边界解析2501_9378609410 小时前
下篇:网络层、数据链路层与应用层:IP、NAT、ARP、DNS 一网打尽ITxiaobing202311 小时前
IP 定位服务怎么选:第三方认可、实测精度和合规边界不是一回事VidDown11 小时前
从视频画面里提取文字:OCR、文字检测与结构化输出阿钱真强道12 小时前
12 嵌入式操作系统 | UDP 服务器编程VidDown13 小时前
文件没问题但网页播不了:播放器接入实战与那些“环境问题liangshanbo121515 小时前
面试题:HTTP/2有哪些升级web打印社区15 小时前
远程打印:WebSocket 与 HTTP 轮询怎么选