Android: Handle Cookie from HTTP Get-Request

混江龙づ霸主 提交于 2019-12-06 11:27:56

问题


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();

回答1:


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: https://stackoverflow.com/a/8280340/1083345



来源:https://stackoverflow.com/questions/9956917/android-handle-cookie-from-http-get-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!