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
相关推荐
Rust研习社21 小时前
使用 Axum 构建高性能异步 Web 服务灰子学技术21 小时前
Envoy HTTP 流量层面的 Metric 指标分析上海云盾-小余21 小时前
海外恶意 UDP 攻击溯源:分层封禁策略与业务兼容平衡方案TimeAground1 天前
HTTP 协议全解:从报文到 HTTP/3,Android 开发者需要知道的一切Diros1g1 天前
如何通过普通网线给另一个设备供网lifewange1 天前
如何设计一个 RESTful APIUnbelievabletobe1 天前
港股api的WebSocket推送如何订阅多只股票TechWayfarer1 天前
IP归属地运营商能解决什么问题?风控/增长/数据平台落地实践(附API代码)TechWayfarer1 天前
IP归属地运营商生产落地进阶:缓存+降级+灰度对账全解析