我正在尝试使用 apache httpclietn-4.2.2 获取“Set Cookie”标头并遇到一些问题。
Firebug 中的标头:
Set-Cookie remixreg_sid=deleted; expires=Thu, 10-Nov-2011 04:32:30 GMT; path=/;
domain=.vk.com remixapi_sid=deleted; expires=Thu, 10-Nov-2011 04:32:30 GMT; path=/;
domain=.vk.com remixrec_sid=deleted; expires=Thu, 10-Nov-2011 04:32:30 GMT; path=/;
domain=.vk.com remixsid=0000000000000000000000000000000000000000000000000000; expires=Mon, 04-Nov-2013 16:10:24 GMT; path=/; domain=.vk.com
我如何尝试获得它:
//location is a header with url I need to do GET request to
Header location = response.getFirstHeader("Location");
HttpGet httpGet = new HttpGet(location.getValue());
httpClient.getParams().setParameter(
//tried to use different policies
ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2965);
Header [] allHeaders=response.getAllHeaders();
在 allHeaders 中,我有除“Set Cookie”之外的所有标题。我有这样的警告:
WARNING: Invalid cookie header: "Set-Cookie: remixlang=0; expires=Mon, 18-Nov-2013
03:21:47 GMT; path=/; domain=.vk.com". Unrecognized cookie header 'Set-Cookie:
remixlang=0; expires=Mon, 18-Nov-2013 03:21:47 GMT; path=/; domain=.vk.com'
Nov 09, 2012 4:31:41 AM org.apache.http.client.protocol.ResponseProcessCookies
processCookies
所以我认为问题在于“到期”日期。
我试图做的事情:
1)无效的cookie标头:过期属性为空时无法解析过期属性 创建自定义CookieSpec并尝试使用它:
httpClient.getCookieSpecs().register("vkCookie", new CookieSpecFactory() {
public CookieSpec newInstance(HttpParams params){
return new VkCookieSpec();
}
});
HttpClientParams.setCookiePolicy(httpClient.getParams(), "vkCookie");
2) 尝试在 httpClient 参数中设置数据格式:
httpClient.getParams().setParameter(CookieSpecPNames.DATE_PATTERNS, Arrays.asList("EEE, dd-MMM-yyyy HH:mm:ss z"));
但我仍然收到这个警告。将不胜感激任何帮助。