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
相关推荐
工控小楠2 小时前
DeviceNet转Modbus TCP网关的远程遥控接收端连接研究midsummer_woo4 小时前
【2025年】解决Burpsuite抓不到https包的问题光芒Shine5 小时前
【物联网-TCP/IP】小白杨树树7 小时前
【WebSocket】SpringBoot项目中使用WebSocket云计算-Security7 小时前
如何理解 IP 数据报中的 TTL?itachi-uchiha8 小时前
命令行以TLS/SSL显式加密方式访问FTP服务器稳联技术9 小时前
实践提炼,EtherNet/IP转PROFINET网关实现乳企数字化工厂增效Icoolkj9 小时前
WebRTC 与 WebSocket 的关联关系红米饭配南瓜汤9 小时前
WebRTC中的几个Rtp*Sender猫头虎12 小时前
[特殊字符]解决 “IDEA 登录失败。不支持早于 14.0 的 GitLab 版本” 问题的几种方法