当前位置: 首页 > 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. 小技巧:自动提示功能消失解决方案...

终极指南:如何使用LeetDown让旧iPhone重获新生

终极指南&#xff1a;如何使用LeetDown让旧iPhone重获新生 【免费下载链接】LeetDown a GUI macOS Downgrade Tool for A6 and A7 iDevices 项目地址: https://gitcode.com/gh_mirrors/le/LeetDown 还在为iPhone 5s或iPad 4升级后卡顿而烦恼吗&#xff1f;您的旧设备运行…...

3分钟掌握猫抓工具:告别网页资源下载烦恼的智能解决方案

3分钟掌握猫抓工具&#xff1a;告别网页资源下载烦恼的智能解决方案 【免费下载链接】cat-catch 猫抓 浏览器资源嗅探扩展 / cat-catch Browser Resource Sniffing Extension 项目地址: https://gitcode.com/GitHub_Trending/ca/cat-catch 你有没有遇到过这样的困扰&…...

Mac Mouse Fix:让普通鼠标在macOS上拥有触控板般的流畅体验

Mac Mouse Fix&#xff1a;让普通鼠标在macOS上拥有触控板般的流畅体验 【免费下载链接】mac-mouse-fix Mac Mouse Fix - Make Your $10 Mouse Better Than an Apple Trackpad! 项目地址: https://gitcode.com/GitHub_Trending/ma/mac-mouse-fix 你是否曾经在macOS上使用…...

避开Conda环境冲突!在Ubuntu 20.04上丝滑安装ROS Noetic的保姆级教程

避开Conda环境冲突&#xff01;在Ubuntu 20.04上丝滑安装ROS Noetic的保姆级教程 当Python数据科学遇上机器人开发&#xff0c;Conda与ROS的环境变量冲突就像两个武林高手在狭窄的走廊里过招——稍有不慎就会两败俱伤。作为同时深耕AI和机器人领域的开发者&#xff0c;我经历过…...

rust 1.95.0 最新版发布:语言特性、编译器、平台支持、标准库、Rustdoc 与兼容性变更全解析

rust 1.95.0 最新版发布&#xff1a;语言特性、编译器、平台支持、标准库、Rustdoc 与兼容性变更全解析 2026年4月16日&#xff0c;Rust 1.95.0 正式发布。作为一次重要版本更新&#xff0c;这一版在语言层、编译器、平台支持、标准库、Rustdoc 以及兼容性方面都带来了相当丰富…...

告别“充不上电”:手把手教你用万用表排查直流快充桩常见故障(附检测点电压实测)

告别“充不上电”&#xff1a;手把手教你用万用表排查直流快充桩常见故障&#xff08;附检测点电压实测&#xff09; 作为一名在充电桩运维一线摸爬滚打多年的"老电工"&#xff0c;我见过太多因为一个小电阻损坏导致整个充电站瘫痪的案例。今天&#xff0c;我就把压箱…...

ngx_set_environment

1 定义 ngx_set_environment 函数 定义在 ./nginx-1.24.0/src/core/nginx.cchar ** ngx_set_environment(ngx_cycle_t *cycle, ngx_uint_t *last) {char **p, **env;ngx_str_t *var;ngx_uint_t i, n;ngx_core_conf_t *ccf;ngx_pool_…...

抖音直播网页端数据采集技术实现方案解析

抖音直播网页端数据采集技术实现方案解析 【免费下载链接】DouyinLiveWebFetcher 抖音直播间网页版的弹幕数据抓取&#xff08;2025最新版本&#xff09; 项目地址: https://gitcode.com/gh_mirrors/do/DouyinLiveWebFetcher DouyinLiveWebFetcher 是一个专注于抖音直播…...

Scroll Reverser终极指南:如何为Mac触控板和鼠标设置独立的滚动方向

Scroll Reverser终极指南&#xff1a;如何为Mac触控板和鼠标设置独立的滚动方向 【免费下载链接】Scroll-Reverser Per-device scrolling prefs on macOS. 项目地址: https://gitcode.com/gh_mirrors/sc/Scroll-Reverser 你是否曾经在Mac上使用外接鼠标时&#xff0c;发…...

Phi-3-Mini-128K实战案例:法律合同长文本分析+关键条款提取效果展示

Phi-3-Mini-128K实战案例&#xff1a;法律合同长文本分析关键条款提取效果展示 1. 引言&#xff1a;当小模型遇上大合同 想象一下&#xff0c;你面前摆着一份长达50页的投资协议&#xff0c;里面密密麻麻全是法律条文。你需要快速找到其中的保密条款、违约责任和争议解决方式…...