Volley ignores Cookie header request

橙三吉。 提交于 2019-12-06 14:19:50
gbaccetta

If you do not need compatibility with Android < 2.3 you just need to add this line of code in your onCreate of the activity or the application. That will activate default cookieManager for all httpURLconnections.

CookieHandler.setDefault(new CookieManager());

Hope this help.

If you need more backwards compatibility you need Cookie management also for HttpClient

Edit:in this latter case follow this answer to pass a custom HttpClientStack: https://stackoverflow.com/a/21271347

There is a problem with Volley header manipulation that I ran into also. Check the source code of HurlStack that comes inside Volley.

Headers inside Volley are put inside Map and sometimes (I still don't know why), Volley gathers headers of the same key (in your case Set-Cookie) one by one ( first it would be this PHPSESSION, and then it will get this path part of your Set-Cookie). As this is a Map, the first one gets overwritten, and you dont get what you want.

My suggestion is to alter the source code of HurlStack in order to get those headers in a list or with different keys (Set-Cookie1, Set-Cookie2, ..).

Also take a look at RetroFit it handles this really nice. Only thing is that with RetroFit you don't get the possibility of canceling the requests.

Hope this helps.

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