Fix issue #415
This commit is contained in:
parent
a3f4d8e6d5
commit
2a68fa01dd
|
@ -267,7 +267,7 @@ public class HttpsConnection {
|
|||
|
||||
|
||||
URL url = new URL(urlConnection);
|
||||
|
||||
if (urlConnection.startsWith("https://")) {
|
||||
if (proxy != null)
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
|
||||
else
|
||||
|
@ -311,6 +311,51 @@ public class HttpsConnection {
|
|||
getSinceMaxId();
|
||||
httpsURLConnection.getInputStream().close();
|
||||
return response;
|
||||
}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);
|
||||
}
|
||||
getSinceMaxId();
|
||||
httpURLConnection.getInputStream().close();
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue