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
相关推荐
wdfk_prog7 小时前
LWIP教程 09:从 `tcp_slowtmr()` 到 Fast Retransmit——TCP 超时重传与重复 ACKZooproxy全球IP代理7 小时前
住宅IP在AI行业中的技术应用:数据采集基础设施的工程实践深蓝电商API7 小时前
HTTP/2 协议逆向:从 Fiddler 抓不到包说起盛世宏博智慧档案7 小时前
一文读懂 PoE+Modbus TCP 温湿度传感器布线规范与故障排查盛世宏博智慧档案9 小时前
多配电室 VLAN 隔离怎么统一监控?IP 温湿度跨网段采集方案fthux10 小时前
开源小工具 Who Arrives:看看你的公网 IP、地区、时区和网络青瓦梦滋10 小时前
【在线五子棋对战】在线用户