为AsyncHttpClient设置Cookie
使用AsyncHttpClient向服务端提交数据,有时需要带cookie。给AsyncHttpClient设置Cookie的方法如下:
AsyncHttpClient myClient = new AsyncHttpClient();
PersistentCookieStore myCookieStore = new PersistentCookieStore(this); BasicClientCookie newCookie = new BasicClientCookie("name1", "value1"); newCookie.setVersion(1); newCookie.setDomain("mydomain.com"); newCookie.setPath("/"); myCookieStore.addCookie(newCookie);
myClient.setCookieStore(myCookieStore);
myClient.post(url, params, new AsyncHttpResponseHandler(){});
参考: http://loopj.com/android-async-http
http://loopj.com/android-async-http/doc/com/loopj/android/http/AsyncHttpClient.html