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
相关推荐
比兔代理7 小时前
正向代理与反向代理技术辨析,为什么代理 IP 属于正向代理K成长日志21 小时前
DALI协议-Part209-颜色控制IPdodo_1 天前
跨境 API 调用不稳定怎么办:出口、超时重试与链路监控的实践碳基修炼1 天前
排查记:本地 devServer 是 http,浏览器却把 302 重定向升级成了 https那年窗外下的雪.2 天前
第 02 天:Linux 权限、inode、目录项与链接那年窗外下的雪.2 天前
AIDC 学习日志|第 27 天|EVPN 多归属收敛时间线与 Leaf2 接管验证j7~2 天前
【Linux】三十八.C++ 手写 HTTP 服务器:裸 socket + fork 多进程,从 HTTP 报文解析到浏览器打开网页小则又沐风a2 天前
深入理解TCP协议----滑动窗口,流量控制captain3762 天前
网络原理(9)-数据链路层yi碗汤园3 天前
MQTT消息队列遥测传输协议