From 068fc7f2e81178e55fa191a13709af64b1a163f6 Mon Sep 17 00:00:00 2001 From: EricsHu <hrr145632> Date: 星期一, 05 十二月 2022 14:27:43 +0800 Subject: [PATCH] 处理编码 --- src/main/java/com/qxueyou/scc/base/util/HttpClient.java | 88 ++++++++++++++++++++++---------------------- 1 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/qxueyou/scc/base/util/HttpClient.java b/src/main/java/com/qxueyou/scc/base/util/HttpClient.java index 0ed3874..3622ad7 100644 --- a/src/main/java/com/qxueyou/scc/base/util/HttpClient.java +++ b/src/main/java/com/qxueyou/scc/base/util/HttpClient.java @@ -75,7 +75,7 @@ } private void init() { - X509TrustManager xtm = new X509TrustManager() { // 创建TrustManager + X509TrustManager xtm = new X509TrustManager() { // 鍒涘缓TrustManager public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } @@ -89,9 +89,9 @@ } }; try { - // TLS1.0与SSL3.0基本上没有太大的差别,可粗略理解为TLS是SSL的继承者,但它们使用的是相同的SSLContext + // TLS1.0涓嶴SL3.0鍩烘湰涓婃病鏈夊お澶х殑宸埆锛屽彲绮楃暐鐞嗚В涓篢LS鏄疭SL鐨勭户鎵胯�咃紝浣嗗畠浠娇鐢ㄧ殑鏄浉鍚岀殑SSLContext SSLContext ctx = SSLContext.getInstance("TLS"); - // 使用TrustManager来初始化该上下文,TrustManager只是被SSL的Socket所使用 + // 浣跨敤TrustManager鏉ュ垵濮嬪寲璇ヤ笂涓嬫枃锛孴rustManager鍙槸琚玈SL鐨凷ocket鎵�浣跨敤 ctx.init(null, new TrustManager[] { xtm }, null); /* @@ -145,13 +145,13 @@ } /** - * 向HTTPS地址发送POST请求 + * 鍚慔TTPS鍦板潃鍙戦�丳OST璇锋眰 * * @param reqURL - * 请求地址 + * 璇锋眰鍦板潃 * @param params - * 请求参数 - * @return 响应内容 + * 璇锋眰鍙傛暟 + * @return 鍝嶅簲鍐呭 */ @SuppressWarnings("unchecked") public String sendStringPostRequest(String reqURL, Map<String, String> params1) { @@ -161,7 +161,7 @@ params = Collections.EMPTY_MAP; } - HttpEntity entity = sendPostRequest(reqURL, params); // 获取响应实体 + HttpEntity entity = sendPostRequest(reqURL, params); // 鑾峰彇鍝嶅簲瀹炰綋 if( null != entity ){ String content = EntityUtils.toString(entity, UTF_8); @@ -184,13 +184,13 @@ } /** - * 向HTTPS地址发送POST请求 + * 鍚慔TTPS鍦板潃鍙戦�丳OST璇锋眰 * * @param reqURL - * 请求地址 + * 璇锋眰鍦板潃 * @param params - * 请求参数 - * @return 响应内容 + * 璇锋眰鍙傛暟 + * @return 鍝嶅簲鍐呭 */ @SuppressWarnings("unchecked") public String sendStringPostRequest(String reqURL, String data) { @@ -198,7 +198,7 @@ StringEntity reqEntity = new StringEntity(data, UTF_8); - HttpEntity entity = sendPostRequest(reqURL, Collections.EMPTY_MAP, reqEntity); // 获取响应实体 + HttpEntity entity = sendPostRequest(reqURL, Collections.EMPTY_MAP, reqEntity); // 鑾峰彇鍝嶅簲瀹炰綋 if( null != entity ){ @@ -223,13 +223,13 @@ } /** - * 向HTTPS地址发送POST请求 + * 鍚慔TTPS鍦板潃鍙戦�丳OST璇锋眰 * * @param reqURL - * 请求地址 + * 璇锋眰鍦板潃 * @param params - * 请求参数 - * @return 响应内容 + * 璇锋眰鍙傛暟 + * @return 鍝嶅簲鍐呭 */ public String sendStringPostRequest(String reqURL, Map<String, String> headerParas1, String data) { Map<String, String> headerParas = headerParas1; @@ -237,7 +237,7 @@ StringEntity reqEntity = new StringEntity(data, UTF_8); - HttpEntity entity = sendPostRequest(reqURL, headerParas, reqEntity); // 获取响应实体 + HttpEntity entity = sendPostRequest(reqURL, headerParas, reqEntity); // 鑾峰彇鍝嶅簲瀹炰綋 if( null != entity ){ String content = EntityUtils.toString(entity, UTF_8); @@ -260,13 +260,13 @@ } /** - * 向HTTPS地址发送POST请求 + * 鍚慔TTPS鍦板潃鍙戦�丳OST璇锋眰 * * @param reqURL - * 请求地址 + * 璇锋眰鍦板潃 * @param params - * 请求参数 - * @return 响应内容 + * 璇锋眰鍙傛暟 + * @return 鍝嶅簲鍐呭 */ @SuppressWarnings("unchecked") public HttpEntity sendPostRequest(String reqURL, Map<String, String> params1) { @@ -319,7 +319,7 @@ Map<String, String> headerParas = headerParas1; try { - HttpPost httpPost = new HttpPost(reqURL); // 创建HttpPost + HttpPost httpPost = new HttpPost(reqURL); // 鍒涘缓HttpPost httpPost.setEntity(reqEntity); headerParas = checkUserAgent(headerParas); @@ -332,18 +332,18 @@ log.debug("request--header:" + header.getName() + ":" + header.getValue()); } - HttpResponse response = httpClient.execute(httpPost); // 执行POST请求 + HttpResponse response = httpClient.execute(httpPost); // 鎵цPOST璇锋眰 headers = response.getAllHeaders(); for (Header header : headers) { log.debug("response--header:" + header.getName() + ":" + header.getValue()); } - HttpEntity entity = response.getEntity(); // 获取响应实体 + HttpEntity entity = response.getEntity(); // 鑾峰彇鍝嶅簲瀹炰綋 this.debug(httpPost.getURI(), response.getStatusLine().getStatusCode(), entity.getContentLength(), entity.getContentType()); if (302 == response.getStatusLine().getStatusCode() && response.containsHeader("location")) { String location = response.getLastHeader("location").getValue(); - log.debug("重定向:" + location); + log.debug("閲嶅畾鍚�:" + location); EntityUtils.consume(entity); return sendPostRequest(location, headerParas, reqEntity); } @@ -366,7 +366,7 @@ Map<String, String> headerParas = headerParas1; try { - HttpDelete httpDelete = new HttpDelete(reqURL); // 创建HttpPost + HttpDelete httpDelete = new HttpDelete(reqURL); // 鍒涘缓HttpPost headerParas = checkUserAgent(headerParas); for (String key : headerParas.keySet()) { @@ -378,12 +378,12 @@ log.debug("request--header:" + header.getName() + ":" + header.getValue()); } - HttpResponse response = httpClient.execute(httpDelete); // 执行POST请求 + HttpResponse response = httpClient.execute(httpDelete); // 鎵цPOST璇锋眰 headers = response.getAllHeaders(); for (Header header : headers) { log.debug("response--header:" + header.getName() + ":" + header.getValue()); } - HttpEntity entity = response.getEntity(); // 获取响应实体 + HttpEntity entity = response.getEntity(); // 鑾峰彇鍝嶅簲瀹炰綋 this.debug(httpDelete.getURI(), response.getStatusLine().getStatusCode(), entity.getContentLength(), entity.getContentType()); @@ -414,17 +414,17 @@ * @param header */ private void debug(URI uri, int code, long length, Header header){ - log.debug("请求地址: " + uri); - log.debug("响应状态: " + code); - log.debug("响应长度: " + length); - log.debug("响应类型: " + header); + log.debug("璇锋眰鍦板潃: " + uri); + log.debug("鍝嶅簲鐘舵��: " + code); + log.debug("鍝嶅簲闀垮害: " + length); + log.debug("鍝嶅簲绫诲瀷: " + header); } public String sendStringPutRequest(String reqURL, Map<String, String> headerParas1, String body) { Map<String, String> headerParas = headerParas1; try { - HttpPut httpPut = new HttpPut(reqURL); // 创建HttpPost + HttpPut httpPut = new HttpPut(reqURL); // 鍒涘缓HttpPost headerParas = checkUserAgent(headerParas); for (String key : headerParas.keySet()) { @@ -439,12 +439,12 @@ StringEntity reqEntity = new StringEntity(body, UTF_8); httpPut.setEntity(reqEntity); - HttpResponse response = httpClient.execute(httpPut); // 执行POST请求 + HttpResponse response = httpClient.execute(httpPut); // 鎵цPOST璇锋眰 headers = response.getAllHeaders(); for (Header header : headers) { log.debug("response--header:" + header.getName() + ":" + header.getValue()); } - HttpEntity entity = response.getEntity(); // 获取响应实体 + HttpEntity entity = response.getEntity(); // 鑾峰彇鍝嶅簲瀹炰綋 this.debug(httpPut.getURI(), response.getStatusLine().getStatusCode(), entity.getContentLength(), entity.getContentType()); @@ -470,7 +470,7 @@ Map<String, String> headerParas = headerParas1; try { - HttpPost httpPost = new HttpPost(reqURL); // 创建HttpPost + HttpPost httpPost = new HttpPost(reqURL); // 鍒涘缓HttpPost BasicHttpEntity requestBody = new BasicHttpEntity(); requestBody.setContent(new ByteArrayInputStream(param.getBytes(UTF_8))); @@ -490,18 +490,18 @@ log.debug("request--param:" + param); - HttpResponse response = httpClient.execute(httpPost); // 执行POST请求 + HttpResponse response = httpClient.execute(httpPost); // 鎵цPOST璇锋眰 headers = response.getAllHeaders(); for (Header header : headers) { log.debug("response--header:" + header.getName() + ":" + header.getValue()); } - HttpEntity entity = response.getEntity(); // 获取响应实体 + HttpEntity entity = response.getEntity(); // 鑾峰彇鍝嶅簲瀹炰綋 this.debug(httpPost.getURI(), response.getStatusLine().getStatusCode(), entity.getContentLength(), entity.getContentType()); if (302 == response.getStatusLine().getStatusCode() && response.containsHeader("location")) { String location = response.getLastHeader("location").getValue(); - log.debug("重定向:" + location); + log.debug("閲嶅畾鍚�:" + location); EntityUtils.consume(entity); return sendPostRequest(location, headerParas, param); } @@ -566,7 +566,7 @@ Map<String, String> params = params1; Map<String, String> headerParas = headerParas1; try { - // HttpGet httpGet = new HttpGet(reqURL); // 创建HttpPost + // HttpGet httpGet = new HttpGet(reqURL); // 鍒涘缓HttpPost headerParas = checkUserAgent(headerParas); @@ -590,19 +590,19 @@ log.debug("request--header:" + header.getName() + ":" + header.getValue()); } - // HttpResponse response = httpClient.execute(httpGet); // 执行POST请求 + // HttpResponse response = httpClient.execute(httpGet); // 鎵цPOST璇锋眰 HttpResponse response = httpClient.execute(request); headers = response.getAllHeaders(); for (Header header : headers) { log.debug("response--header:" + header.getName() + ":" + header.getValue()); } - HttpEntity entity = response.getEntity(); // 获取响应实体 + HttpEntity entity = response.getEntity(); // 鑾峰彇鍝嶅簲瀹炰綋 this.debug(request.getURI(), response.getStatusLine().getStatusCode(), entity.getContentLength(), entity.getContentType()); if (302 == response.getStatusLine().getStatusCode() && response.containsHeader("location")) { String location = response.getLastHeader("location").getValue(); - log.debug("重定向"); + log.debug("閲嶅畾鍚�"); return sendGetRequestAsResponse(location, headerParas, params); } -- Gitblit v1.8.0