From 96ee0584b86518e8796a843963449900c5033fb3 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Wed, 30 May 2018 19:48:17 +0800 Subject: [PATCH] --- src/org/redkale/util/Utility.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/org/redkale/util/Utility.java b/src/org/redkale/util/Utility.java index d7c77bf40..c831eb8fd 100644 --- a/src/org/redkale/util/Utility.java +++ b/src/org/redkale/util/Utility.java @@ -1676,6 +1676,7 @@ public final class Utility { public static ByteArrayOutputStream remoteHttpContent(SSLContext ctx, String method, String url, int timeout, Map headers, String body) throws IOException { HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); + boolean opening = true; try { conn.setConnectTimeout(timeout > 0 ? timeout : 3000); conn.setReadTimeout(timeout > 0 ? timeout : 3000); @@ -1700,6 +1701,7 @@ public final class Utility { if (rs == 301 || rs == 302) { String newurl = conn.getHeaderField("Location"); conn.disconnect(); + opening = false; return remoteHttpContent(ctx, method, newurl, timeout, headers, body); } InputStream in = (rs < 400 || rs == 404) && rs != 405 ? conn.getInputStream() : conn.getErrorStream(); @@ -1712,7 +1714,7 @@ public final class Utility { } return out; } finally { - conn.disconnect(); + if (opening) conn.disconnect(); } }