From 4923370897783c2f335c6b88000287d759d57310 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Wed, 5 Feb 2020 15:25:28 +0800 Subject: [PATCH] fix: #661 --- .../org/jackhuang/hmcl/game/LauncherHelper.java | 2 +- .../org/jackhuang/hmcl/util/io/NetworkUtils.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java index 52a1ff581..b6b63e34c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java @@ -162,7 +162,7 @@ public final class LauncherHelper { } }) .thenRunAsync(Schedulers.javafx(), () -> emitStatus(LoadingState.LOGGING_IN)) - .thenSupplyAsync(i18n("account.methods"), () -> { + .thenSupplyAsync(i18n("launch.state.logging_in"), () -> { try { return account.logIn(); } catch (CredentialExpiredException e) { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NetworkUtils.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NetworkUtils.java index 11330f8f2..7a761069e 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NetworkUtils.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NetworkUtils.java @@ -106,6 +106,10 @@ public final class NetworkUtils { conn.setReadTimeout(15000); conn.setInstanceFollowRedirects(false); Map> properties = conn.getRequestProperties(); + String method = conn.getRequestMethod(); + boolean doInput = conn.getDoInput(); + boolean doOutput = conn.getDoOutput(); + boolean useCaches = conn.getUseCaches(); int code = conn.getResponseCode(); if (code >= 300 && code <= 307 && code != 306 && code != 304) { String newURL = conn.getHeaderField("Location"); @@ -117,6 +121,10 @@ public final class NetworkUtils { HttpURLConnection redirected = (HttpURLConnection) new URL(conn.getURL(), encodeLocation(newURL)).openConnection(); properties.forEach((key, value) -> value.forEach(element -> redirected.addRequestProperty(key, element))); + redirected.setRequestMethod(method); + redirected.setDoInput(doInput); + redirected.setDoOutput(doOutput); + redirected.setUseCaches(useCaches); conn = redirected; ++redirect; } else { @@ -127,7 +135,9 @@ public final class NetworkUtils { } public static String doGet(URL url) throws IOException { - return IOUtils.readFullyAsString(createConnection(url).getInputStream()); + HttpURLConnection con = createConnection(url); + con = resolveConnection(con); + return IOUtils.readFullyAsString(con.getInputStream()); } public static String doPost(URL u, Map params) throws IOException { @@ -149,9 +159,10 @@ public final class NetworkUtils { HttpURLConnection con = createConnection(url); con.setRequestMethod("POST"); - con.setDoOutput(true); con.setRequestProperty("Content-Type", contentType + "; charset=utf-8"); con.setRequestProperty("Content-Length", "" + bytes.length); + con.setDoOutput(true); + con = resolveConnection(con); try (OutputStream os = con.getOutputStream()) { os.write(bytes); }