我固定在我的应用程序崩溃和错误,当我宣布一个cookie存储,但它不保存cookies或者出了问题在其他位置。
起初,我把这些2线:
AsyncHttpClient client = new AsyncHttpClient();
PersistentCookieStore myCookieStore;
然后,我有一个POST:
public void postRequestLogin(String url, RequestParams params) {
myCookieStore = new PersistentCookieStore(this);
client.post(url, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
client.setCookieStore(myCookieStore);
System.out.println(response);
if(response.contains("Login successful!")) {
TextView lblStatus = (TextView)findViewById(R.id.lblStatus);
lblStatus.setText("Login successful!");
getRequest("url");
} else {
TextView lblStatus = (TextView)findViewById(R.id.lblStatus);
lblStatus.setText("Login failed!");
TextView source = (TextView)findViewById(R.id.response_request);
source.setText(response);
}
}
});
}
那么它应该保存Logincookies和使用它的GET请求:
public void getRequest(String url) {
myCookieStore = new PersistentCookieStore(this);
client.get(url, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
client.setCookieStore(myCookieStore);
System.out.println(response);
TextView responseview = (TextView) findViewById(R.id.response_request);
responseview.setText(response);
}
});
}
但它不使用的cookie。 当我做的GET请求我已经注销。
编辑:我忘了说,我用一个lib从本教程: http://loopj.com/android-async-http/