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
相关推荐
傲世仙尊3 小时前
HTTP起步-URL域名解析与协议的本质ControlRookie3 小时前
第27篇_综合排障|从现象反查状态、错误码、指标和连接快照泡海椒4 小时前
JQuick-Excel 字段映射实战:用 MAPPING 固化 Excel 表头与业务字段契约wdfk_prog4 小时前
Wi-Fi Direct 教程 05:control socket 与 eloop——P2P_FIND 怎样进入 wpa_supplicant 命令解析器ITxiaobing202320 小时前
自研 IP 库与 AppsFlyer 判定不一致的排查实践天天喝旺仔20 小时前
gRPC 底层原理:HTTP/2 多路复用、Protobuf 序列化与四种流模式刚及格的陆拾伍21 小时前
Wi-Fi核心知识精要:从频段到帧结构全解析xfan_me1 天前
SSL 证书落地应用与网站安全加固YumiProxy1 天前
动态IP冲突排查实战:从ARP检测到DHCP地址池的完整链路CHENKONG_CK1 天前
RFID 赋能汽车零部件涂装产线,构建全流程数字化追溯体系