diff --git a/hutool-http/src/main/java/cn/hutool/http/cookie/GlobalCookieManager.java b/hutool-http/src/main/java/cn/hutool/http/cookie/GlobalCookieManager.java index e815e7263..303bcdddd 100644 --- a/hutool-http/src/main/java/cn/hutool/http/cookie/GlobalCookieManager.java +++ b/hutool-http/src/main/java/cn/hutool/http/cookie/GlobalCookieManager.java @@ -15,7 +15,7 @@ import java.util.Map; /** * 全局Cookie管理器,只针对Hutool请求有效 - * + * * @author Looly * @since 4.5.15 */ @@ -26,19 +26,19 @@ public class GlobalCookieManager { static { cookieManager = new CookieManager(new ThreadLocalCookieStore(), CookiePolicy.ACCEPT_ALL); } - + /** * 自定义{@link CookieManager} - * + * * @param customCookieManager 自定义的{@link CookieManager} */ public static void setCookieManager(CookieManager customCookieManager) { cookieManager = customCookieManager; } - + /** * 获取全局{@link CookieManager} - * + * * @return {@link CookieManager} */ public static CookieManager getCookieManager() { @@ -58,7 +58,7 @@ public class GlobalCookieManager { /** * 将本地存储的Cookie信息附带到Http请求中,不覆盖用户定义好的Cookie - * + * * @param conn {@link HttpConnection} */ public static void add(HttpConnection conn) { @@ -74,14 +74,13 @@ public class GlobalCookieManager { throw new IORuntimeException(e); } - // 不覆盖模式回填Cookie头,这样用户定义的Cookie将优先 conn.header(cookieHeader, false); } /** * 存储响应的Cookie信息到本地 - * + * * @param conn {@link HttpConnection} */ public static void store(HttpConnection conn) { diff --git a/hutool-http/src/test/java/cn/hutool/http/Issue2658Test.java b/hutool-http/src/test/java/cn/hutool/http/Issue2658Test.java new file mode 100755 index 000000000..47aaf5534 --- /dev/null +++ b/hutool-http/src/test/java/cn/hutool/http/Issue2658Test.java @@ -0,0 +1,22 @@ +package cn.hutool.http; + +import cn.hutool.core.lang.Console; +import cn.hutool.http.cookie.GlobalCookieManager; +import org.junit.Ignore; +import org.junit.Test; + +import java.net.HttpCookie; +import java.util.List; + +public class Issue2658Test { + + @SuppressWarnings("resource") + @Test + @Ignore + public void getWithCookieTest(){ + HttpRequest.get("https://www.baidu.com/").execute(); + final List cookies = GlobalCookieManager.getCookieManager().getCookieStore().getCookies(); + Console.log("###" + cookies); + HttpRequest.get("https://www.baidu.com/").execute(); + } +}