【发布时间】:2012-01-06 23:24:15
【问题描述】:
所以这就是我的应用程序目前的设置方式:
1.) 登录活动。 2.) 登录后,可能会启动其他使用 PHP 脚本的活动,这些脚本需要登录时发送的 cookie。
我在我的应用程序中使用了一个 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 来简单地获取响应的字符串。没什么特别的。
我了解我的 cookie 被拒绝的原因是由于“非法路径属性”(我在 /mobile-api/login.php 运行脚本,而 cookie 将返回路径仅为“/”用于trackallthethings),但无论如何我都愿意接受cookies。有没有办法做到这一点?
【问题讨论】:
标签: java android cookies httpclient