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
相关推荐
YuMiao2 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题不可能的是3 天前
前端 SSE 流式请求三种实现方案全解析Jony_5 天前
高可用移动网络连接chilix5 天前
Linux 跨网段路由转发配置gihigo19987 天前
基于TCP协议实现视频采集与通信古译汉书7 天前
【IoT死磕系列】Day 7:只传8字节怎么控机械臂?学习工业控制 CANopen 的“对象字典”(附企业级源码)白太岁7 天前
通信:(5) 电路交换、报文交换与分组交换前网易架构师-高司机7 天前
带标注的驾驶员安全带识别数据集,识别率99.5%,可识别有无系安全带,支持yolo,coco json,pascal voc xml格式EasyGBS7 天前
国标安全升级:GB28181平台EasyGBS支持GB35114协议的应用场景与核心优势逍遥德7 天前
Maven教程.01- settings.xml 文件<profile>使用详解