使用带有 cookie 的 AndroidHttpClient 会给我混合 200 ok 和 403 禁止响应。我不确定我做错了什么。
我以以下方式使用 AndroidHttpClient :
我有几个后台线程类,每个类都执行以下操作:
HttpGet get...
HttpClient client = AndroidHttpClient.newInstance("Android");
HttpContext http_context = HttpSupport.getHttpContextInstance();
CookieStore cookie_store = HttpSupport.getCookieStoreInstance();
http_context.setAttribute(ClientContext.COOKIE_STORE, cookie_store);
client.execute(
HttpSupport 是一个有两个静态字段的类;一个 CookieStore 和一个 HttpContext:
public class HttpSupport {
private static HttpContext _context;
private static CookieStore _cookieStore;
public static synchronized HttpContext getHttpContextInstance() {
if (_context == null) {
_context = new BasicHttpContext();
}
return _context;
}
public static synchronized CookieStore getCookieStoreInstance() {
if (_cookieStore == null) {
_cookieStore = new BasicCookieStore();
}
return _cookieStore;
}
}
可以在应用程序中有多个 AndroidHttpClient 实例吗?我是否正确存储了 cookie?