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
相关推荐
extrao11 小时前
🚀 Kea DHCP4 自动分配系统完整搭建喵个咪15 小时前
Go-Wind HTTP 服务器从入门到精通不做菜鸟的网工2 天前
BGP特性明月_清风4 天前
开发者网络概念全扫盲:一篇搞定刘马想放假5 天前
Modbus 全栈技术解析:TCP、RTU、ASCII、RTU over TCP王二端茶倒水6 天前
一套可落地的无线运营方案,不能只管 AP,还要管用户、计费和运维162723816086 天前
EtherCAT 分布式时钟(DC)原理与配置实战:把多轴真正"对齐到同一时刻"王二端茶倒水6 天前
宽带无线项目,怎么从一次性交付变成长期运营收入?Goodbye6 天前
大模型无状态架构:从 HTTP 协议到 Harness AI 工程的深度解析