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

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …...

CVPR 2025 MIMO: 支持视觉指代和像素grounding 的医学视觉语言模型

CVPR 2025 | MIMO&#xff1a;支持视觉指代和像素对齐的医学视觉语言模型 论文信息 标题&#xff1a;MIMO: A medical vision language model with visual referring multimodal input and pixel grounding multimodal output作者&#xff1a;Yanyuan Chen, Dexuan Xu, Yu Hu…...

云计算——弹性云计算器(ECS)

弹性云服务器&#xff1a;ECS 概述 云计算重构了ICT系统&#xff0c;云计算平台厂商推出使得厂家能够主要关注应用管理而非平台管理的云平台&#xff0c;包含如下主要概念。 ECS&#xff08;Elastic Cloud Server&#xff09;&#xff1a;即弹性云服务器&#xff0c;是云计算…...

Qt Http Server模块功能及架构

Qt Http Server 是 Qt 6.0 中引入的一个新模块&#xff0c;它提供了一个轻量级的 HTTP 服务器实现&#xff0c;主要用于构建基于 HTTP 的应用程序和服务。 功能介绍&#xff1a; 主要功能 HTTP服务器功能&#xff1a; 支持 HTTP/1.1 协议 简单的请求/响应处理模型 支持 GET…...

重启Eureka集群中的节点,对已经注册的服务有什么影响

先看答案&#xff0c;如果正确地操作&#xff0c;重启Eureka集群中的节点&#xff0c;对已经注册的服务影响非常小&#xff0c;甚至可以做到无感知。 但如果操作不当&#xff0c;可能会引发短暂的服务发现问题。 下面我们从Eureka的核心工作原理来详细分析这个问题。 Eureka的…...

在Ubuntu24上采用Wine打开SourceInsight

1. 安装wine sudo apt install wine 2. 安装32位库支持,SourceInsight是32位程序 sudo dpkg --add-architecture i386 sudo apt update sudo apt install wine32:i386 3. 验证安装 wine --version 4. 安装必要的字体和库(解决显示问题) sudo apt install fonts-wqy…...

算法:模拟

1.替换所有的问号 1576. 替换所有的问号 - 力扣&#xff08;LeetCode&#xff09; ​遍历字符串​&#xff1a;通过外层循环逐一检查每个字符。​遇到 ? 时处理​&#xff1a; 内层循环遍历小写字母&#xff08;a 到 z&#xff09;。对每个字母检查是否满足&#xff1a; ​与…...

MySQL 知识小结(一)

一、my.cnf配置详解 我们知道安装MySQL有两种方式来安装咱们的MySQL数据库&#xff0c;分别是二进制安装编译数据库或者使用三方yum来进行安装,第三方yum的安装相对于二进制压缩包的安装更快捷&#xff0c;但是文件存放起来数据比较冗余&#xff0c;用二进制能够更好管理咱们M…...

【C++进阶篇】智能指针

C内存管理终极指南&#xff1a;智能指针从入门到源码剖析 一. 智能指针1.1 auto_ptr1.2 unique_ptr1.3 shared_ptr1.4 make_shared 二. 原理三. shared_ptr循环引用问题三. 线程安全问题四. 内存泄漏4.1 什么是内存泄漏4.2 危害4.3 避免内存泄漏 五. 最后 一. 智能指针 智能指…...

论文阅读笔记——Muffin: Testing Deep Learning Libraries via Neural Architecture Fuzzing

Muffin 论文 现有方法 CRADLE 和 LEMON&#xff0c;依赖模型推理阶段输出进行差分测试&#xff0c;但在训练阶段是不可行的&#xff0c;因为训练阶段直到最后才有固定输出&#xff0c;中间过程是不断变化的。API 库覆盖低&#xff0c;因为各个 API 都是在各种具体场景下使用。…...