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
相关推荐
wuyk5553 分钟前
【Socket 进阶之路】第 3 章 TCP 三次握手 & 四次挥手深度剖析|连接建立、断开、状态机、TIME_WAIT 核心工程问题sibylyue11 小时前
WebSocket双向长连接传输通道小小、码农11 小时前
C++11右值引用与移动语义 —— 从拷贝资源到转移资源80s77713 小时前
动态ip地址分配通常是由_动态IP与静态IP之间的区别TechVoyager_824616 小时前
IT9205技术解析:4K60 HDR over IP与视频墙的单芯片实现路径隐擎fox16 小时前
跨越传输层防线:深入 TCP/IP 协议栈指纹(p0f)原理与 Python 原始套接字检测实战2601_9628857216 小时前
不用 SDK 也能取 A 股数据:AlphaFeed REST API用 cURL/HTTP 直连教程Multipath71216 小时前
远程可视操控:多链路聚合如何把“不确定”变“可管理”Jeremy_WW17 小时前
802.3协议解读 01:116章节 200 Gb/s 和 400 Gb/s 网络介绍 I为思念酝酿的痛19 小时前
应用层协议HTTPS