当前位置: 首页 > news >正文

Java Post请求参数格式为XML

方式一:
public static void PostXml1(String url, String xml) throws IOException {OkHttpClient client = new OkHttpClient().newBuilder().build();//okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/xml");okhttp3.MediaType mediaType = okhttp3.MediaType.parse("text/xml");//RequestBody body = RequestBody.create(mediaType, "<messages xmlns=\"http://www.neusoft.com/hit/rhin\">\r\n    <heartbeat>\r\n        0\r\n    </heartbeat>\r\n    <switchset>\r\n        <authority>\r\n            <authoritytype>\r\n                0\r\n            </authoritytype>\r\n            <username/>\r\n            <userpwd/>\r\n            <license/>\r\n        </authority>\r\n        <visitor>\r\n            <!-- 调用方22位机构编码 -->\r\n            <sourceorgan>\r\n                3301060000000000000000\r\n            </sourceorgan>\r\n            <!-- 调用方10位接入系统编码 -->\r\n            <sourcedomain>\r\n                3301000013\r\n            </sourcedomain>\r\n        </visitor>\r\n        d\r\n        <serviceinf>\r\n            <servicecode>\r\n                XBSJCJCJJ:PCRWHHQJ\r\n            </servicecode>\r\n        </serviceinf>\r\n        <provider>\r\n            <targetorgan/>\r\n            <targetdomain/>\r\n        </provider>\r\n        <route/>\r\n        <process/>\r\n    </switchset>\r\n    <business>\r\n        <standardcode/>\r\n        <requestset>\r\n            <reqcondition/>\r\n            <reqpaging>\r\n                0\r\n            </reqpaging>\r\n            <reqpageindex>\r\n                -1\r\n            </reqpageindex>\r\n            <reqpageset>\r\n                0\r\n            </reqpageset>\r\n        </requestset>\r\n        <datacompress>\r\n            0\r\n        </datacompress>\r\n        <daqtaskid>\r\n            20231109000000001\r\n        </daqtaskid>\r\n        <businessdata>\r\n            <!--声明类型 0:总声明/1:单次声明-->\r\n            <declaretype>\r\n                0\r\n            </declaretype>\r\n            <!--采集类型 0:增量采集-->\r\n            <collecttype>\r\n                0\r\n            </collecttype>\r\n            <!--声明门(急)诊挂号登记业务上传6月6号一天增量数据的情况 -->\r\n            <totaldeclare>\r\n                <!--交换标准编码 示例:门(急)诊挂号登记-->\r\n                <colrescode>\r\n                    REQ.C0101.0302.02\r\n                </colrescode>\r\n                <!--任务数 -->\r\n                <tasknum>\r\n                    5\r\n                </tasknum>\r\n                <!--数据开始时间 -->\r\n                <begindatetime>\r\n                    20221124000000\r\n                </begindatetime>\r\n                <!--数据结束时间 -->\r\n                <enddatetime>\r\n                    20221124235959\r\n                </enddatetime>\r\n                <!--一个数据集的整体描述 -->\r\n                <tdeclare>\r\n                    <!--门(急)诊挂号登记-->\r\n                    <setcode>\r\n                        C0101.0302.02\r\n                    </setcode>\r\n                    <!--记录数 -->\r\n                    <datanum>\r\n                        500\r\n                    </datanum>\r\n                </tdeclare>\r\n            </totaldeclare>\r\n        </businessdata>\r\n        <returnmessage>\r\n            <retcode/>\r\n            <rettext/>\r\n        </returnmessage>\r\n    </business>\r\n    <extendset/>\r\n</messages>");RequestBody body = RequestBody.create(mediaType, "<messages xmlns=\"http://www.neusoft.com/hit/rhin\"><heartbeat>0</heartbeat><switchset><authority><authoritytype>0</authoritytype><username/><userpwd/><license/></authority><visitor><!-- 调用方22位机构编码 --><sourceorgan>3301060000000000000000</sourceorgan><!-- 调用方10位接入系统编码 --><sourcedomain>3301000013</sourcedomain></visitor>d<serviceinf><servicecode>XBSJCJCJJ:PCRWHHQJ</servicecode></serviceinf><provider><targetorgan/><targetdomain/></provider><route/><process/></switchset><business><standardcode/><requestset><reqcondition/><reqpaging>0</reqpaging><reqpageindex>-1</reqpageindex><reqpageset>0</reqpageset></requestset><datacompress>0</datacompress><daqtaskid>20231109000000001</daqtaskid><businessdata><!--声明类型 0:总声明/1:单次声明-->\r\n            <declaretype>\r\n                0\r\n            </declaretype>\r\n            <!--采集类型 0:增量采集-->\r\n            <collecttype>\r\n                0\r\n            </collecttype>\r\n            <!--声明门(急)诊挂号登记业务上传6月6号一天增量数据的情况 -->\r\n            <totaldeclare>\r\n                <!--交换标准编码 示例:门(急)诊挂号登记-->\r\n                <colrescode>\r\n                    REQ.C0101.0302.02\r\n                </colrescode>\r\n                <!--任务数 -->\r\n                <tasknum>\r\n                    5\r\n                </tasknum>\r\n                <!--数据开始时间 -->\r\n                <begindatetime>20221124000000</begindatetime><!--数据结束时间 --><enddatetime>20221124235959</enddatetime><!--一个数据集的整体描述 --><tdeclare><!--门(急)诊挂号登记--><setcode>C0101.0302.02</setcode><!--记录数 --><datanum>500</datanum></tdeclare></totaldeclare></businessdata><returnmessage><retcode/><rettext/></returnmessage></business><extendset/></messages>");//RequestBody body = RequestBody.create(mediaType, "");Request request = new Request.Builder().url("https://www.baidu.com/sc/totalDeclare?short-access=aaa68ed6397a4595b4d3e1c37533b6ac").method("POST", body).addHeader("Content-Type", "text/xml")//.addHeader("short-access-token", "aaa68ed6397a4595b4d3e1c37533b6ac").build();
Response response = client.newCall(request).execute();String responseBody = response.body().toString();System.out.println(responseBody);}
方式二:
private String invoke(String requestUrl, String requestXml) throws Exception {StringBuilder builder = new StringBuilder();HttpURLConnection connection = getHttpURLConnection(requestUrl);// 输出流OutputStream outputStream = connection.getOutputStream();outputStream.write(requestXml.getBytes(StandardCharsets.UTF_8));outputStream.close();// 输入流InputStream inputStream = connection.getInputStream();InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);BufferedReader bufferedReader = new BufferedReader(inputStreamReader);String line = null;while ((line = bufferedReader.readLine()) != null) {builder.append(line);}bufferedReader.close();inputStreamReader.close();inputStream.close();connection.disconnect();return builder.toString();
}/*** 获取HttpURLConnection*/
private HttpURLConnection getHttpURLConnection(String requestUrl) throws Exception {URL url = new URL(requestUrl);HttpURLConnection connection = (HttpURLConnection) url.openConnection();connection.setConnectTimeout(3000);connection.setReadTimeout(3000);connection.setDoOutput(true);connection.setDoInput(true);connection.setUseCaches(false);connection.setRequestMethod("POST");connection.setRequestProperty("accept", "*/*");connection.setRequestProperty("connection", "Keep-Alive");connection.setRequestProperty("Content-type", "application/xml");	return connection;
}
方式三:
<dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.13</version>
</dependency>
public static String postXmlRequest(String url, String xml) throws Exception {HttpPost post = new HttpPost(url);post.setHeader("Content-type", "text/xml");//post.setEntity(new StringEntity(xml));post.setEntity(new StringEntity(xml, StandardCharsets.UTF_8));CloseableHttpClient client = HttpClients.createDefault();CloseableHttpResponse response = client.execute(post);return response.getStatusLine().getStatusCode() == 200 ? EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8) : null;
}

相关文章:

Java Post请求参数格式为XML

方式一&#xff1a; public static void PostXml1(String url, String xml) throws IOException {OkHttpClient client new OkHttpClient().newBuilder().build();//okhttp3.MediaType mediaType okhttp3.MediaType.parse("application/xml");okhttp3.MediaType m…...

Windows 安装 JDK 8 和 JDK 17 和多版本JDK切换

目录 下载 JDK安装 JDK配置环境变量卸载 JDK卸载 JDK 8卸载 JDK 17 下载 JDK JDK 8 下载地址&#xff1a;https://www.aliyundrive.com/s/koYe1SVRg76 JDK 17 下载地址&#xff1a; https://www.aliyundrive.com/s/tBcbUtAHTbg 安装 JDK 点击可执行文件 jdk-8u291-windows-…...

SpringData、SparkStreaming和Flink集成Elasticsearch

本文代码链接&#xff1a;https://download.csdn.net/download/shangjg03/88522188 1 Spring Data框架集成 1.1 Spring Data框架介绍 Spring Data是一个用于简化数据库、非关系型数据库、索引库访问&#xff0c;并支持云服务的开源框架。其主要目标是使得对数据的访问变得方便快…...

中国电子学会2023年09月份青少年软件编程Python等级考试试卷六级真题(含答案)

2023-09 Python六级真题 分数&#xff1a;100 题数&#xff1a;38 测试时长&#xff1a;60min 一、单选题(共25题&#xff0c;共50分) 1. 以下选项中&#xff0c;不是tkinter变量类型的是&#xff1f;&#xff08;D &#xff09;(2分) A.IntVar() B.StringVar() C.Do…...

基于STM32设计的智能水母投喂器(华为云IOT)

基于STM32设计的智能水母养殖系统 一、设计简述 1.1 项目背景 水母是一种非常美丽和神秘的生物,在许多人的眼中,它不仅是一种宽广的海洋世界中的一道美丽的风景线,同时也是一种珍贵的实验动物和养殖资源。随着水母的养殖需求不断增多,一个高效、智能、可控的水母养殖系统…...

合成数据加速机器视觉学习

虽然机器学习在基于视觉的自动化中的应用正在增长&#xff0c;但许多行业都面临着挑战&#xff0c;并难以在其计算机视觉应用中实施它。这在很大程度上是由于需要收集许多图像&#xff0c;以及与准确注释这些图像中的不同产品相关的挑战。 该领域的最新趋势之一是利用合成数据…...

物业管理服务预约小程序的效果如何

物业所涵盖的场景比较多&#xff0c;如小区住宅、办公楼、医院、度假区等&#xff0c;而所涵盖的业务也非常广&#xff0c;而在实际管理中&#xff0c;无论对外还是对内也存在一定难题&#xff1a; 1、品牌展示难、内部管理难 物业需求度比较广&#xff0c;设置跨区域也可以&…...

ORA-00257: Archiver error. Connect AS SYSDBA only until resolved错误解决

错误的原因&#xff1a;是因为服务器分配空间不足&#xff0c;数据库归档日志满导致系统数据库登陆失败。 解决办法&#xff1a;1.删除以前的日志 2.增大归档日志的容量 3.关闭归档模式 一、删除以前的容量 1.登录账号后&#xff0c;查看ORACLE_BASE目录 【oraclelocalhost~】$…...

backbone:从AlexNet到...(持续补充ing)

文章目录 Introduction(前言知识)代码参考卷积、池化输出退化1*1卷积减少或增加通道数自然的减少计算量解决了什么问题,达到了什么样的效果AlexNet整体结构如下VGGNet网络结构如下,D、E分别代表VGG-16、VGG-19下图为VGG-16ResNet结构如下DenseNet结构如下Dense Block——特…...

FiRa标准——MAC实现(二)

在IEEE 802.15.4z标准中&#xff0c;最关键的就是引入了STS&#xff08;加扰时间戳序列&#xff09;&#xff0c;实现了安全测距&#xff0c;大大提高了测距应用的安全性能。在FiRa的实现中&#xff0c;其密钥派生功能是非常重要的一个部分&#xff0c;本文首先对FiRa MAC中加密…...

oracle中分组函数LISTAGG

前言 Oracle中的 GROUP_CONCAT 函数用于将多行数据合并为一行&#xff0c;并以指定的分隔符分隔各个值。在Oracle中&#xff0c;没有直接的GROUP_CONCAT函数&#xff0c;但可以使用 LISTAGG 函数来实现类似的功能。 如何使用 1、使用SELECT语句选择需要合并的列&#xff0c;…...

深度学习pytorch之hub模块

pytorchhub模块里面有很多模型 https://pytorch.org/hub/ github网址&#xff1a;https://github.com/pytorch/pytorch import torch model torch.hub.load(pytorch/vision:v0.10.0, fcn_resnet50, pretrainedTrue) # or # model torch.hub.load(pytorch/vision:v0.10.0, fc…...

LeetCode 2258. 逃离火灾:BFS

【LetMeFly】2258.逃离火灾 力扣题目链接&#xff1a;https://leetcode.cn/problems/escape-the-spreading-fire/ 给你一个下标从 0 开始大小为 m x n 的二维整数数组 grid &#xff0c;它表示一个网格图。每个格子为下面 3 个值之一&#xff1a; 0 表示草地。1 表示着火的格…...

C# PaddleInference.PP-HumanSeg 人像分割 替换背景色

效果 项目 VS2022.net4.8OpenCvSharp4Sdcb.PaddleInference 包含4个分割模型 modnet-hrnet_w18 modnet-mobilenetv2 ppmatting-hrnet_w18-human_512 ppmattingv2-stdc1-human_512 代码 using OpenCvSharp; using Sdcb.PaddleInference; using System; using System.Col…...

Java 变量初始化的两种方式和优缺点比较

第一种初始化方式&#xff1a;&#xff08;优先推荐&#xff09; String fileRename null; File fileToSave null; 这种方式将变量的作用域限定在循环外部&#xff0c;即在整个代码块中都可以使用这些变量。初始值为null表示变量在开始时没有具体的数值。 这种方式更好的…...

15.三数之和

​题目来源&#xff1a; leetcode题目&#xff0c;网址&#xff1a;15. 三数之和 - 力扣&#xff08;LeetCode&#xff09; 解题思路&#xff1a; 1.三重循环暴力遍历&#xff0c;超时原因&#xff0c;三重循环复杂度太高 2.双重循环哈希表&#xff0c;超时原因&#xff0c;哈…...

竞赛选题 深度学习疲劳驾驶检测 opencv python

文章目录 0 前言1 课题背景2 实现目标3 当前市面上疲劳驾驶检测的方法4 相关数据集5 基于头部姿态的驾驶疲劳检测5.1 如何确定疲劳状态5.2 算法步骤5.3 打瞌睡判断 6 基于CNN与SVM的疲劳检测方法6.1 网络结构6.2 疲劳图像分类训练6.3 训练结果 7 最后 0 前言 &#x1f525; 优…...

PROFINET和UDP、MODBUS-RTU通信速度对比实验

这篇博客我们介绍PROFINET 和MODBUS-RTU通信实验时的数据刷新速度,以及这种速度不同对控制系统带来的挑战都有哪些,在介绍这篇对比实验之前大家可以参考下面的文章链接: S7-1200PLC和SMART PLC的PN智能从站通信 S7-200 SMART 和 S7-1200PLC进行PROFINET IO通信-CSDN博客文…...

CSS3 多媒体查询、网格布局

一、CSS3多媒体查询&#xff1a; CSS3 多媒体查询继承了CSS2多媒体类型的所有思想&#xff0c;取代了查找设备的类型。CSS3根据设置自适应显示。 多媒体查询语法&#xff1a; media not|only mediatype and (expressions) { CSS 代码...; } not: not是用来排除掉某些特定…...

SpringBoot基础(九)-- 配置文件优先级

目录 1. 3种格式的配置文件的优先级 2. 案例演示 小结: 3. 小技巧:自动提示功能消失解决方案...

调用支付宝接口响应40004 SYSTEM_ERROR问题排查

在对接支付宝API的时候&#xff0c;遇到了一些问题&#xff0c;记录一下排查过程。 Body:{"datadigital_fincloud_generalsaas_face_certify_initialize_response":{"msg":"Business Failed","code":"40004","sub_msg…...

渗透实战PortSwigger靶场-XSS Lab 14:大多数标签和属性被阻止

<script>标签被拦截 我们需要把全部可用的 tag 和 event 进行暴力破解 XSS cheat sheet&#xff1a; https://portswigger.net/web-security/cross-site-scripting/cheat-sheet 通过爆破发现body可以用 再把全部 events 放进去爆破 这些 event 全部可用 <body onres…...

spring:实例工厂方法获取bean

spring处理使用静态工厂方法获取bean实例&#xff0c;也可以通过实例工厂方法获取bean实例。 实例工厂方法步骤如下&#xff1a; 定义实例工厂类&#xff08;Java代码&#xff09;&#xff0c;定义实例工厂&#xff08;xml&#xff09;&#xff0c;定义调用实例工厂&#xff…...

uniapp中使用aixos 报错

问题&#xff1a; 在uniapp中使用aixos&#xff0c;运行后报如下错误&#xff1a; AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build 解决方案&…...

根据万维钢·精英日课6的内容,使用AI(2025)可以参考以下方法:

根据万维钢精英日课6的内容&#xff0c;使用AI&#xff08;2025&#xff09;可以参考以下方法&#xff1a; 四个洞见 模型已经比人聪明&#xff1a;以ChatGPT o3为代表的AI非常强大&#xff0c;能运用高级理论解释道理、引用最新学术论文&#xff0c;生成对顶尖科学家都有用的…...

【碎碎念】宝可梦 Mesh GO : 基于MESH网络的口袋妖怪 宝可梦GO游戏自组网系统

目录 游戏说明《宝可梦 Mesh GO》 —— 局域宝可梦探索Pokmon GO 类游戏核心理念应用场景Mesh 特性 宝可梦玩法融合设计游戏构想要素1. 地图探索&#xff08;基于物理空间 广播范围&#xff09;2. 野生宝可梦生成与广播3. 对战系统4. 道具与通信5. 延伸玩法 安全性设计 技术选…...

视觉slam十四讲实践部分记录——ch2、ch3

ch2 一、使用g++编译.cpp为可执行文件并运行(P30) g++ helloSLAM.cpp ./a.out运行 二、使用cmake编译 mkdir build cd build cmake .. makeCMakeCache.txt 文件仍然指向旧的目录。这表明在源代码目录中可能还存在旧的 CMakeCache.txt 文件,或者在构建过程中仍然引用了旧的路…...

安宝特案例丨Vuzix AR智能眼镜集成专业软件,助力卢森堡医院药房转型,赢得辉瑞创新奖

在Vuzix M400 AR智能眼镜的助力下&#xff0c;卢森堡罗伯特舒曼医院&#xff08;the Robert Schuman Hospitals, HRS&#xff09;凭借在无菌制剂生产流程中引入增强现实技术&#xff08;AR&#xff09;创新项目&#xff0c;荣获了2024年6月7日由卢森堡医院药剂师协会&#xff0…...

【笔记】WSL 中 Rust 安装与测试完整记录

#工作记录 WSL 中 Rust 安装与测试完整记录 1. 运行环境 系统&#xff1a;Ubuntu 24.04 LTS (WSL2)架构&#xff1a;x86_64 (GNU/Linux)Rust 版本&#xff1a;rustc 1.87.0 (2025-05-09)Cargo 版本&#xff1a;cargo 1.87.0 (2025-05-06) 2. 安装 Rust 2.1 使用 Rust 官方安…...

Java数值运算常见陷阱与规避方法

整数除法中的舍入问题 问题现象 当开发者预期进行浮点除法却误用整数除法时,会出现小数部分被截断的情况。典型错误模式如下: void process(int value) {double half = value / 2; // 整数除法导致截断// 使用half变量 }此时...