Skip to content

Commit 34907f3

Browse files
author
huanglh
committed
TS-6644 修复上传文件设置代理不生效
1 parent 36475f2 commit 34907f3

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/main/java/cn/jiguang/common/connection/NativeHttpClient.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,7 @@ private ResponseWrapper _doRequest(String url, String content,
133133
try {
134134
URL aUrl = new URL(url);
135135

136-
if (null != _proxy) {
137-
conn = (HttpURLConnection) aUrl.openConnection(_proxy.getNetProxy());
138-
if (_proxy.isAuthenticationNeeded()) {
139-
conn.setRequestProperty("Proxy-Authorization", _proxy.getProxyAuthorization());
140-
}
141-
} else {
142-
conn = (HttpURLConnection) aUrl.openConnection();
143-
}
136+
conn = getConnectionByUrl(aUrl);
144137

145138
conn.setConnectTimeout(_connectionTimeout);
146139
conn.setReadTimeout(_readTimeout);
@@ -315,7 +308,7 @@ private String formUpload(String urlStr, Map<String, String> textMap,
315308
String BOUNDARY = "---------------------------" + System.currentTimeMillis();
316309
try {
317310
URL url = new URL(urlStr);
318-
conn = (HttpURLConnection) url.openConnection();
311+
conn = getConnectionByUrl(url);
319312
conn.setConnectTimeout(5000);
320313
conn.setReadTimeout(30000);
321314
conn.setDoOutput(true);
@@ -423,6 +416,19 @@ private String formUpload(String urlStr, Map<String, String> textMap,
423416
return res;
424417
}
425418

419+
public HttpURLConnection getConnectionByUrl(URL url) throws IOException {
420+
HttpURLConnection conn;
421+
if (null != _proxy) {
422+
conn = (HttpURLConnection) url.openConnection(_proxy.getNetProxy());
423+
if (_proxy.isAuthenticationNeeded()) {
424+
conn.setRequestProperty("Proxy-Authorization", _proxy.getProxyAuthorization());
425+
}
426+
} else {
427+
conn = (HttpURLConnection) url.openConnection();
428+
}
429+
return conn;
430+
}
431+
426432
private static class SimpleHostnameVerifier implements HostnameVerifier {
427433

428434
public boolean verify(String hostname, SSLSession session) {

0 commit comments

Comments
 (0)