问题描述
我通过)。
我用DefaultHttpClient这一点。
随着GET响应,该网站发送的cookie,我想存储进一步POST请求。
我的问题是, client.getCookieStore()的getCookies()
总是收到饼干的空列表。
如果我打开(我打算网站insted的),我收到正确的饼干,但该网站我有工作,似乎发送cookie以其他方式(这是一个邮差邮件列表缓和页)
我可以看到在Firefox cookie管理器的cookie的分别,而不是在网络萤火虫/饼干面板(为什么?)。然而InternetExplorer的HttpWatchProfessional显示该cookie记录通信时....
有一些小的差异,我发送的cookie www.google.com和我的目标网站之间观察到:在HttpWatchProfessional,从谷歌这些cookie被标记为方向:派,而从我的网站饼干被标记为方向:接收。
(如何能在谷歌的cookie被发送,而我之前清空浏览器/ cookie缓存?)
谁能解释的差异吗?
我的code是以下内容:
DefaultHttpClient客户端=新DefaultHttpClient();
HTTPGET HTTPGET =新HTTPGET(URL);
HTT presponse执行= client.execute(HTTPGET);
清单< Cookie和GT;饼干= client.getCookieStore()的getCookies()。
经过进一步调查,我发现该Cookie已收到,但实际上拒绝了HttpClient的,由于路径中的cookie,它不同与从所谓的URL。
我找到了解决办法的:
I am working on an app which shall log in to a web site (via http://......?password=xyz).I use DefaultHttpClient for this.Along with the GET response, the website sends a cookie, which I want to store for further POST requests.
My problem is that client.getCookieStore().getCookies()
always receives an empty list of cookies.
If I open http://www.google.com (insted of my intended website), I receive the cookies properly, but the website I am working with, seems to send the cookie in some other way (it's a MailMan mailing list moderating page)
I can see the respective cookie in Firefox cookie manager, but not in Firebug network/cookie panel (why?). InternetExplorer HttpWatchProfessional however shows the cookie when recording the traffic....
There is some small difference, I observed between the cookies www.google.com sent and my target website: In HttpWatchProfessional, those cookies from google are marked as "Direction: sent", while the cookie from my website are marked as "Direction: Received".(how can the google cookies be sent, while I cleared browser/cookie cache just before?)
Can someone explain the difference to me?
My code is the following:
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse execute = client.execute(httpGet);
List<Cookie> cookies = client.getCookieStore().getCookies();
After further investigation, I found out that the cookie was received, but actually rejected by the httpclient, due to a path the cookie, which differed to that from the called URL.
I found the solution at:http://stackoverflow.com/a/8280340/1083345
这篇关于安卓:从HTTP GET请求处理的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!