Fix issue #415
This commit is contained in:
parent
a3f4d8e6d5
commit
2a68fa01dd
|
@ -267,50 +267,95 @@ public class HttpsConnection {
|
||||||
|
|
||||||
|
|
||||||
URL url = new URL(urlConnection);
|
URL url = new URL(urlConnection);
|
||||||
|
if (urlConnection.startsWith("https://")) {
|
||||||
if (proxy != null)
|
if (proxy != null)
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||||
else
|
else
|
||||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||||
httpsURLConnection.setConnectTimeout(30 * 1000);
|
httpsURLConnection.setConnectTimeout(30 * 1000);
|
||||||
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
|
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
|
||||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||||
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
httpsURLConnection.setRequestProperty("Accept", "application/json");
|
||||||
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
|
||||||
httpsURLConnection.setRequestMethod("GET");
|
httpsURLConnection.setRequestMethod("GET");
|
||||||
httpsURLConnection.setDefaultUseCaches(true);
|
httpsURLConnection.setDefaultUseCaches(true);
|
||||||
httpsURLConnection.setUseCaches(true);
|
httpsURLConnection.setUseCaches(true);
|
||||||
String response;
|
String response;
|
||||||
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
|
||||||
getSinceMaxId();
|
getSinceMaxId();
|
||||||
response = converToString(httpsURLConnection.getInputStream());
|
response = converToString(httpsURLConnection.getInputStream());
|
||||||
} else {
|
} else {
|
||||||
String error = null;
|
String error = null;
|
||||||
if (httpsURLConnection.getErrorStream() != null) {
|
if (httpsURLConnection.getErrorStream() != null) {
|
||||||
InputStream stream = httpsURLConnection.getErrorStream();
|
InputStream stream = httpsURLConnection.getErrorStream();
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
stream = httpsURLConnection.getInputStream();
|
stream = httpsURLConnection.getInputStream();
|
||||||
}
|
}
|
||||||
try (Scanner scanner = new Scanner(stream)) {
|
try (Scanner scanner = new Scanner(stream)) {
|
||||||
scanner.useDelimiter("\\Z");
|
scanner.useDelimiter("\\Z");
|
||||||
if (scanner.hasNext()) {
|
if (scanner.hasNext()) {
|
||||||
error = scanner.next();
|
error = scanner.next();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
int responseCode = httpsURLConnection.getResponseCode();
|
||||||
|
try {
|
||||||
|
httpsURLConnection.getInputStream().close();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
throw new HttpsConnectionException(responseCode, error);
|
||||||
}
|
}
|
||||||
int responseCode = httpsURLConnection.getResponseCode();
|
getSinceMaxId();
|
||||||
try {
|
httpsURLConnection.getInputStream().close();
|
||||||
httpsURLConnection.getInputStream().close();
|
return response;
|
||||||
} catch (Exception ignored) {
|
}else{
|
||||||
|
if (proxy != null)
|
||||||
|
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
|
||||||
|
else
|
||||||
|
httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||||
|
httpURLConnection.setConnectTimeout(30 * 1000);
|
||||||
|
httpURLConnection.setRequestProperty("http.keepAlive", "false");
|
||||||
|
httpURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
httpURLConnection.setRequestProperty("Accept", "application/json");
|
||||||
|
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
|
httpURLConnection.setRequestMethod("GET");
|
||||||
|
httpURLConnection.setDefaultUseCaches(true);
|
||||||
|
httpURLConnection.setUseCaches(true);
|
||||||
|
String response;
|
||||||
|
if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
|
||||||
|
getSinceMaxId();
|
||||||
|
response = converToString(httpURLConnection.getInputStream());
|
||||||
|
} else {
|
||||||
|
String error = null;
|
||||||
|
if (httpURLConnection.getErrorStream() != null) {
|
||||||
|
InputStream stream = httpURLConnection.getErrorStream();
|
||||||
|
if (stream == null) {
|
||||||
|
stream = httpURLConnection.getInputStream();
|
||||||
|
}
|
||||||
|
try (Scanner scanner = new Scanner(stream)) {
|
||||||
|
scanner.useDelimiter("\\Z");
|
||||||
|
if (scanner.hasNext()) {
|
||||||
|
error = scanner.next();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int responseCode = httpURLConnection.getResponseCode();
|
||||||
|
try {
|
||||||
|
httpURLConnection.getInputStream().close();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
throw new HttpsConnectionException(responseCode, error);
|
||||||
}
|
}
|
||||||
throw new HttpsConnectionException(responseCode, error);
|
getSinceMaxId();
|
||||||
|
httpURLConnection.getInputStream().close();
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
getSinceMaxId();
|
|
||||||
httpsURLConnection.getInputStream().close();
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue