摘要:Android - AQuery Cookie
這次遇到某種麻煩,
使用AQuery做登入,登入後要記錄對方的Cookie,在每次呼叫時要回傳Cookie
結果,竟然被我找到了。
http://stackoverflow.com/questions/20786545/set-cookie-using-android-query-ajaxcallback
List<Cookie> cookies;
AQuery query = new AQuery(this);
query.ajax("your url", JSONObject.class, new AjaxCallback<String>() {
@Override
public void callback(String url, String json, AjaxStatus status) {
cookies = status.getCookies(); // We are saving the cookies in our variable
}
});
AQuery query = new AQuery(this);
AjaxCallback<JSONObject> ajaxCallback = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, String json, AjaxStatus status) {
cookies = status.getCookies(); // Save the cookies in every requests you made
}
}
for (Cookie cookie : cookies) {
ajaxCallback.cookie(cookie.getName(), cookie.getValue());
//Here we are setting the cookie info.
}
query.ajax("your url", JSONObject.class, ajaxCallback);
就這樣我處理完畢,功力又大增,XD