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
相关推荐
mister_guo13 小时前
HTTP 和 RPC:从一次干饭说清它们的区别严谨的麻辣烫13 小时前
Python HTTP 连接池怎么用?从连接复用到请求异常排查K成长日志14 小时前
BLE Host层L2CAP -- 配置参数选项幻智星科技16 小时前
纯FPGA网络通信实现微秒级确定性延迟码林鼠17 小时前
flutter网络http请求入门教程-dioLsetea18 小时前
curl访问HTTPS返回304却没有正文:条件请求、缓存与证书验收排查zxanz120 小时前
免费 SSL 证书的隐性成本:续期压力、稳定性与商业风险评估zzu123zsw20 小时前
面对多 RPC 扇入超时崩溃:深入 asyncTool 核心 DAG 编排与线程池隔离防护福娃筱欢20 小时前
金仓数据库配置SSL双向认证K成长日志20 小时前
BLE Host层L2CAP -- 状态机