所以这是我的应用程序的设置方式:
1.)登录活动.
2.)登录后,可能会启动其他活动,这些活动使用需要登录时发送的cookie的PHP脚本.
我在我的应用程序中使用一个HttpClient来确保使用相同的cookie,但我的问题是我收到了3个cookie中的2个被拒绝.我不关心cookie的有效性,但我确实需要它们被接受. I tried setting the CookiePolicy,但这也没有奏效.这就是logcat所说的:
11-26 10:33:57.613: WARN/ResponseProcessCookies(271): Cookie rejected: "[version: 0] [name: cookie_user_id][value: 1][domain: www.trackallthethings.com][path: trackallthethings][expiry: Sun Nov 25 11:33:00 CST 2012]". Illegal path attribute "trackallthethings". Path of origin: "/mobile-api/login.PHP"
11-26 10:33:57.593: WARN/ResponseProcessCookies(271): Cookie rejected: "[version: 0][name: cookie_session_id][value: 1985208971][domain: www.trackallthethings.com][path: trackallthethings][expiry: Sun Nov 25 11:33:00 CST 2012]". Illegal path attribute "trackallthethings". Path of origin: "/mobile-api/login.PHP"
我确信我的实际代码是正确的(我的应用程序仍然正确登录,只是不接受上述cookie),但无论如何它在这里:
HttpGet httpget = new HttpGet(//MY URL);
HttpResponse response;
response = Main.httpclient.execute(httpget);
httpentity entity = response.getEntity();
InputStream in = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
从这里我使用StringBuilder来简单地获取响应的String.没有什么花哨.
我理解我的cookie被拒绝的原因是因为“非法路径属性”(我在/mobile-api/login.PHP运行脚本,而cookie将返回路径为“/”,用于trackallthethings) ,但无论如何我想接受饼干.有没有办法做到这一点?
解决方法:
您面临的问题似乎是出于隐私/安全目的而设计的.通常,不允许任何资源设置它将无法接收的cookie.在这里,您尝试使用资源/mobile-api/login.PHP中的路径trackallthethings设置cookie,这显然不起作用.
这里有以下两个选项
>使用两个资源都可访问的路径设置cookie(这可能是root’/’)OR
>定义自定义cookie策略并注册自己的cookie支持.这是related documentation和example.
希望这可以帮助.