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
相关推荐
qq_448011166 小时前
python HTTP请求同时返回为JSON的异常处理老蒋新思维9 小时前
创客匠人:认知即资产 ——AI 时代创始人 IP 知识变现的底层逻辑ZXF_H10 小时前
Linux tcpdump抓包实践(以http为例)白驹过隙^^10 小时前
OB-USP-AGENT安装使用方法爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ10 小时前
日志打印配置:logback-spring.xml配置;info和error完全区分了,并且按时间拆分了sdszoe492211 小时前
IP地址规划与VLSM技术北京耐用通信11 小时前
耐达讯自动化网关:用Profinet唤醒沉睡的DeviceNet流量计,省下60%改造费!Running_slave12 小时前
聊聊TCP滑窗的一些有趣“病症”想用offer打牌13 小时前
一站式了解跨域问题伊玛目的门徒14 小时前
HTTP SSE 流式响应处理:调用腾讯 智能应用开发平台ADP智能体的 API