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
相关推荐
IpdataCloud7 小时前
IPv6商用数据的IP离线库能解决哪些业务问题?适用场景与接入指南古城小栈10 小时前
hey 你好 “压测”java1234_小锋12 小时前
MyBatis中XML映射有哪些标签?思麟呀12 小时前
Select多路转接wl851113 小时前
SAP CPI 教程003 如何抓取Http适配器异常信息大腕先生13 小时前
通用分页超详细介绍(附带源代码解析&页面展示效果)飞Link13 小时前
【常见协议与服务】HTTP1.1、HTTP2、HTTP3:性能到底差在哪lularible15 小时前
PTP协议精讲(3.7):传输层实现——PTP报文的“高速公路“S1998_1997111609•X15 小时前
RSS/RSA\-SSh,G\-bps^&&·iOS\Cd/,~…:cade?_code in/@$&¥_buy=ID card|want_M_GEN.M*L郝学胜-神的一滴15 小时前
深入epoll反应堆模型:从libevent源码看高性能IO设计精髓