From 34907f325e594f9bd43dbf8ef4c82a393f926c80 Mon Sep 17 00:00:00 2001 From: huanglh Date: Wed, 27 Oct 2021 18:50:32 +0800 Subject: [PATCH] =?UTF-8?q?TS-6644=20=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AE=BE=E7=BD=AE=E4=BB=A3=E7=90=86=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/connection/NativeHttpClient.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/cn/jiguang/common/connection/NativeHttpClient.java b/src/main/java/cn/jiguang/common/connection/NativeHttpClient.java index 8a386ac..ab1ccf0 100644 --- a/src/main/java/cn/jiguang/common/connection/NativeHttpClient.java +++ b/src/main/java/cn/jiguang/common/connection/NativeHttpClient.java @@ -133,14 +133,7 @@ private ResponseWrapper _doRequest(String url, String content, try { URL aUrl = new URL(url); - if (null != _proxy) { - conn = (HttpURLConnection) aUrl.openConnection(_proxy.getNetProxy()); - if (_proxy.isAuthenticationNeeded()) { - conn.setRequestProperty("Proxy-Authorization", _proxy.getProxyAuthorization()); - } - } else { - conn = (HttpURLConnection) aUrl.openConnection(); - } + conn = getConnectionByUrl(aUrl); conn.setConnectTimeout(_connectionTimeout); conn.setReadTimeout(_readTimeout); @@ -315,7 +308,7 @@ private String formUpload(String urlStr, Map textMap, String BOUNDARY = "---------------------------" + System.currentTimeMillis(); try { URL url = new URL(urlStr); - conn = (HttpURLConnection) url.openConnection(); + conn = getConnectionByUrl(url); conn.setConnectTimeout(5000); conn.setReadTimeout(30000); conn.setDoOutput(true); @@ -423,6 +416,19 @@ private String formUpload(String urlStr, Map textMap, return res; } + public HttpURLConnection getConnectionByUrl(URL url) throws IOException { + HttpURLConnection conn; + if (null != _proxy) { + conn = (HttpURLConnection) url.openConnection(_proxy.getNetProxy()); + if (_proxy.isAuthenticationNeeded()) { + conn.setRequestProperty("Proxy-Authorization", _proxy.getProxyAuthorization()); + } + } else { + conn = (HttpURLConnection) url.openConnection(); + } + return conn; + } + private static class SimpleHostnameVerifier implements HostnameVerifier { public boolean verify(String hostname, SSLSession session) {