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
相关推荐
王二端茶倒水7 小时前
宽带无线项目,怎么从一次性交付变成长期运营收入?Goodbye8 小时前
大模型无状态架构:从 HTTP 协议到 Harness AI 工程的深度解析用户2530171996271 天前
第6篇:从技术到产品 — Ghost Proxifier 的设计哲学用户2530171996271 天前
第3篇:注入的艺术 — Ghost Proxifier 核心架构拆解王二端茶倒水3 天前
商业 WiFi 不是免费上网,而是门店数字化的入口霜落长河6 天前
抛弃TCP改用UDP,HTTP3怎么了?程序员mine7 天前
HTTPS-TLS加密与证书完全指南(中)之歆7 天前
现代 HTTP 客户端深度解析:Fetch 与 Axios酉鬼女又兒8 天前
零基础入门计算机网络运输层:端到端通信核心作用、端口号分类规则、复用分用工作机制及UDP与TCP协议全方位对比详解