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
相关推荐
冰暮流星12 小时前
flask之http请求方法K成长日志13 小时前
BLE协议之设备地址liulilittle14 小时前
KCC 边界缺陷深度分析:六问题根源与解决方案PixelBai15 小时前
JSON转XML使用教程:从入门到精通犹豫的哑铃17 小时前
WebSocket 协议funnycoffee12317 小时前
lacp报文占多少字节?报文的目的maclihao lihao18 小时前
Tcp Socket从零开始的代码生活_18 小时前
Linux select 多路转接详解2401_8685347818 小时前
网络安全:信息加密、认证(鉴别)、数字签名(CA)、密钥安全分发国强_dev1 天前
技术探讨:使用 stunnel 加密转发数据库连接时,如何获取客户端真实 IP?