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
相关推荐
草根站起来8 小时前
“双算法SSL证书”伪方案、国产SSL证书营销话术与等保绑定乱象批判江华森10 小时前
Web 开发基础:HTTP 与 RESTher_heart13 小时前
把 ChatGPT 5.6 放进需求评审和测试设计之后,我反而减少了“一次成稿”的期待AI产品实战18 小时前
Gradle打包生成dependencies.xml详解coderhuo20 小时前
libcurl blind sleep导致的耗时问题treesforest20 小时前
做内容平台,IP地址精准定位和IP高精度定位查询怎么帮我们提升用户留存wang_shu_mo_ran21 小时前
网络编程(二):UDP数据报在客户端与服务端之间的传输永久鳕21 小时前
WebSocket 连接成功但行情不更新,应该先查哪几个状态?mudtools1 天前
HttpUtils:一个编译时生成的声明式 HTTP 客户端框架卖萌的斜阳2 天前
W55MH32L-EVB 上手测评:硬件 TCP/IP 加持的以太网单片机,MicroPython 零门槛开发