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
相关推荐
李白的天不白24 分钟前
http https就叫_这个吧14 小时前
IDEA Mybatis xml文件,实现sql语句联想,自动填入补充上海云盾-小余14 小时前
源站隐藏实战:规避裸 IP 被直接攻击的完整方案johnny23314 小时前
WebDAV概述、原理、拓展:SMB、ZeroByte代码中介商15 小时前
HTTP进化史:从1.0到3.0的核心变革范什么特西17 小时前
配置文件xml和propertiessweet丶18 小时前
MQTT在iOS中的应用实践ALINX技术博客18 小时前
【黑金云课堂】FPGA技术教程Vitis开发:TCP以太网通信matrixmind819 小时前
HTTPX:Python 下一代 HTTP 客户端W.W.H.20 小时前
Ping 与 TCP:网络连通性探测的两种维度