我在通过我的服务器进行身份验证时遇到了一些问题。
当我手动尝试通过 Postman 等 Google 插件设置 cookie 时,它可以工作,但通过 android 设备或模拟器完成时不起作用。
这是我的那部分代码:
String url = "www.thisismyendpoint.com";
String ci_session = "ci_session=token";
CookieStore cookieStore = new BasicCookieStore();
BasicClientCookie stdCookie = new BasicClientCookie("Cookie",ci_session);
cookieStore.addCookie(stdCookie);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE,
cookieStore);
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpClient.execute(httppost, localContext);
这是我在 logcat 中的回复:
02-19 16:43:47.149: D/response(27539): response: <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
02-19 16:43:47.149: D/response(27539): <h4>A PHP Error was encountered</h4>
02-19 16:43:47.149: D/response(27539): <p>Severity: Notice</p>
02-19 16:43:47.149: D/response(27539): <p>Message: Undefined index: ci_session</p>
02-19 16:43:47.149: D/response(27539): <p>Filename: controllers/test.php</p>
02-19 16:43:47.149: D/response(27539): <p>Line Number: 28</p>
02-19 16:43:47.149: D/response(27539): </div>
难道我做错了什么?我也尝试将 ci_session 设置到标题中,但同样它不起作用。请指教。谢谢!