小编Col*_*edy的帖子

升级到Apache HttpClient 4.4后,它不会发送带有请求的cookie

我正在使用Apache HttpClient向我们的内部API服务器发送请求.服务器需要身份验证,并且需要使用身份验证令牌设置cookie.

直到HttpClient 4.3.6这已经工作正常,但在4.4及以上它已停止发送请求cookie.我的cookie域设置为.subdomain.mycompany.com,适用于4.3.6,但不适用于4.4及更高版本.如果我更具体,并将完整主机作为cookie域,即host.subdomain.mycompany.com,它可以工作,但这不是一个解决方案.

这是一个类似于我正在做的代码片段:

public CloseableHttpResponse execute(CloseableHttpClient httpClient) throws IOException {
    BasicClientCookie cookie = new BasicClientCookie("cookieName", "myAuthtoken");
    cookie.setPath("/");
    cookie.setDomain(".subdomain.mycompany.com");
    cookie.setSecure(false);
    HttpContext localContext = new BasicHttpContext(parentContext);
    CookieStore cookieStore = new BasicCookieStore();
    cookieStore.addCookie(cookie);
    localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
    return httpClient.execute(target, request, localContext);
}
Run Code Online (Sandbox Code Playgroud)

httpClient已经构造并传递到此代码中,该代码设置了auth cookie.

我看到了这个,类似的Cookie在Apache httpclient 4.4中被忽略了,但在我的情况下,cookie没有被发送到服务器.

打开HttpClient中的线路登录后,我可以在4.3.6中看到以下内容,但不会在4.4及以上版本中看到:

DEBUG [org.apache.http.client.protocol.RequestAddCookies] Cookie [version: 0][name: cookieName][value: authToken][domain: .subdomain.mycompany.com][path: /][expiry: Wed Jul 15 16:07:05 IST 2015] match [host.subdomain.mycompany.com:80/myApi]
Run Code Online (Sandbox Code Playgroud)

这让我觉得这与cookie域匹配有关.有人有主意吗?谢谢.

java cookies apache-httpclient-4.x

4
推荐指数
1
解决办法
1647
查看次数

标签 统计

apache-httpclient-4.x ×1

cookies ×1

java ×1