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
相关推荐
moonless02221 天前
FastAPI框架,这一小篇就能搞懂精髓。FPGA_Linuxer2 天前
FPGA 40 DAC线缆和光模块带光纤实现40G UDP差异real 12 天前
传输层协议UDPl1t3 天前
利用美团龙猫用libxml2编写XML转CSV文件C程序ftpeak3 天前
从零开始使用 axum-server 构建 HTTP/HTTPS 服务hsjkdhs3 天前
网络编程之UDP广播与粘包问题yzx9910133 天前
接口协议全解析:从HTTP到gRPC,如何选择适合你的通信方案?板鸭〈小号〉3 天前
UDP-Server(3)chat聊天室weixin_456904273 天前
使用HTTPS 服务在浏览器端使用摄像头的方式解析疯狂的维修3 天前
关于Gateway configration studio软件配置网关