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 11:18
本文是转载文章,点击查看原文
如有侵权,请联系 xyy@jishuzhan.net 删除
相关推荐
codingandsleeping18 分钟前
OPTIONS 预检请求海滩上的那乌克丽丽3 小时前
通过websocket给服务端发送订单催单提醒消息codingandsleeping3 小时前
DNS 解析规则笨手笨脚の3 小时前
详解 Https 和加密、摘要、签名、数字证书小冯的编程学习之路5 小时前
【HTTP】:应用层协议HTTP(1)言成言成啊5 小时前
手撕TCP内网穿透及配置树莓派serve the people5 小时前
ip route show 命令详解昊昊该干饭了6 小时前
数据采集爬虫三要素:User-Agent、随机延迟、代理ip秋名RG6 小时前
HTTP 1.1 比 HTTP1.0 多了什么?(详尽版)上海云盾-高防顾问7 小时前
高防IP可以防御什么类型攻击?解析其核心防护能力与应用场景