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
相关推荐
我命由我1234521 分钟前
6-2.Python 异常处理 - 异常捕获(捕获指定异常、常见异常类型、异常信息)严谨的麻辣烫14 小时前
静态 ISP 代理请求超时怎么排查?Python 与 curl 实战FPGA小迷弟17 小时前
FPGA开发Vivado Block Design/Vitis/SDK/xlinx/开发教程,保姆级别,一看就会!FPGA小迷弟17 小时前
基于FPGA实现智能网卡的概念,什么是智能网卡jaysee-sjc1 天前
【苍穹外卖】Day10:定时任务与 WebSocket 实时提醒实战幻智星科技1 天前
我砍掉了FPGA里的ARM核项目反而提前交付了cyf311 天前
半小时玩转RDMA:从零跑通高速网络通信泡海椒1 天前
JQuick-SQL JQuickTable 模型:XML 动态 SQL 的表封装边界奇牙coding1 天前
doubao-seed-2.1-pro 报 HTTP 401 怎么办?Key 正确也要检查请求头和端点砺星Leetx1 天前
工业总线选型与对接实战:PROFINET、EtherCAT、EtherNet/IP、PROFIBUS、Modbus-TCP 与 CC-Link