Skip to content

Commit

Permalink
TS-6644 修复上传文件设置代理不生效
Browse files Browse the repository at this point in the history
  • Loading branch information
huanglh committed Oct 27, 2021
1 parent 36475f2 commit 34907f3
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/main/java/cn/jiguang/common/connection/NativeHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -315,7 +308,7 @@ private String formUpload(String urlStr, Map<String, String> 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);
Expand Down Expand Up @@ -423,6 +416,19 @@ private String formUpload(String urlStr, Map<String, String> 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) {
Expand Down

0 comments on commit 34907f3

Please sign in to comment.