From c560f1a14ae1fc468d90e50e6a32d805295875da Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期一, 01 九月 2025 15:35:59 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/2.0' into 2.0
---
cloud-server-other/src/main/java/com/dsh/other/util/HttpClientUtil.java | 34 +++++++++++++++++++++++++++++++++-
1 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/cloud-server-other/src/main/java/com/dsh/other/util/HttpClientUtil.java b/cloud-server-other/src/main/java/com/dsh/other/util/HttpClientUtil.java
index b33680b..f4fe16c 100644
--- a/cloud-server-other/src/main/java/com/dsh/other/util/HttpClientUtil.java
+++ b/cloud-server-other/src/main/java/com/dsh/other/util/HttpClientUtil.java
@@ -244,7 +244,39 @@
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
}
-
+ public static String pushHttpsRequsetXml1(String url, String xml, Map<String, String> header, String certPassword, String certPath, String certType) throws Exception {
+ HttpPost httpPost = new HttpPost(url);
+ for (String key : header.keySet()) {
+ httpPost.setHeader(key, header.get(key));
+ }
+ httpPost.setHeader("Content-Type", "application/xml");
+ httpPost.setEntity(new StringEntity(xml, "UTF-8"));
+ CloseableHttpClient httpCline = initCert1(certPassword, certPath, certType);
+ CloseableHttpResponse httpResponse = httpCline.execute(httpPost);
+ String content = null;
+ if (httpResponse.getStatusLine().getStatusCode() == 200) {
+ content = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
+ } else {
+ content = "返回状态码:" + httpResponse.getStatusLine() + "。" + EntityUtils.toString(httpResponse.getEntity());
+ }
+ close(httpResponse);
+ httpCline.close();
+ return content;
+ }
+ private static CloseableHttpClient initCert1(String key, String certPath, String certType) throws Exception {
+ KeyStore keyStore = KeyStore.getInstance(certType);
+ InputStream inputStream = new FileInputStream(new File(certPath));
+ try {
+ keyStore.load(inputStream, key.toCharArray());
+ } finally {
+ inputStream.close();
+ }
+ SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, key.toCharArray()).build();
+ SSLConnectionSocketFactory sslsf =
+ new SSLConnectionSocketFactory(sslcontext, null, null,
+ SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
+ return HttpClients.custom().setSSLSocketFactory(sslsf).build();
+ }
/**
* 关闭资源
--
Gitblit v1.7.1