This commit is contained in:
tom79 2020-03-27 18:31:46 +01:00
parent a3f4d8e6d5
commit 2a68fa01dd
1 changed files with 84 additions and 39 deletions

View File

@ -267,50 +267,95 @@ public class HttpsConnection {
URL url = new URL(urlConnection);
if (proxy != null)
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
else
httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setConnectTimeout(30 * 1000);
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
httpsURLConnection.setRequestProperty("Accept", "application/json");
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
httpsURLConnection.setRequestMethod("GET");
httpsURLConnection.setDefaultUseCaches(true);
httpsURLConnection.setUseCaches(true);
String response;
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
getSinceMaxId();
response = converToString(httpsURLConnection.getInputStream());
} else {
String error = null;
if (httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
if (scanner.hasNext()) {
error = scanner.next();
if (urlConnection.startsWith("https://")) {
if (proxy != null)
httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
else
httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setConnectTimeout(30 * 1000);
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
httpsURLConnection.setRequestProperty("Accept", "application/json");
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
httpsURLConnection.setRequestMethod("GET");
httpsURLConnection.setDefaultUseCaches(true);
httpsURLConnection.setUseCaches(true);
String response;
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
getSinceMaxId();
response = converToString(httpsURLConnection.getInputStream());
} else {
String error = null;
if (httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
if (scanner.hasNext()) {
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();
try {
httpsURLConnection.getInputStream().close();
} catch (Exception ignored) {
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);
}
throw new HttpsConnectionException(responseCode, error);
getSinceMaxId();
httpURLConnection.getInputStream().close();
return response;
}
getSinceMaxId();
httpsURLConnection.getInputStream().close();
return response;
}