當我聲明一個cookie存儲時,我在應用程序中修復了崩潰和錯誤,但它不保存cookie或其他位置出錯。請求不使用保存的Cookie在PersistentCookieStore
起初,我把這些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);
}
});
}
但它不使用cookies。當我執行GET請求時,我已經註銷。
編輯:我忘了說,我用一個lib從本教程:http://loopj.com/android-async-http/
讓您的標題具體化非常重要,因爲這會讓知道如何提供幫助的人更容易看到您的問題。您不需要使用「Android」或「Java」等詞語,因爲問題已經有了標籤。 – 2013-03-27 19:58:17