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
相关推荐
7ACE8 小时前
Wireshark TS | 接收数据超出接收窗口续huluang9 小时前
XML文档差异分析工具:深入解析Word XML结构变化llxxyy卢10 小时前
HTTP 头部参数数据注入测试sqlilabs less 18duration~1 天前
TCP 首部格式せいしゅん青春之我1 天前
【JavaEE初阶】TCP核心机制10——异常情况的处理蒜香拿铁1 天前
Angular【http服务端交互】报错小能手1 天前
计算机网络自顶向下方法11——应用层 详解HTTP/3universe_011 天前
前端八股之HTTP奋斗的蛋黄1 天前
TCP/IP 四层模型:网络协议的分工与协作未孤_有青山1 天前
库卡机器人通讯-EtherKRL-XML格式