⑴ android 怎麼從httpResponse獲取cookie
HttpRequest類和HttpResponse類提供了Cookie屬性,可以獲取你要的信息
然後你要顯示的控制項。text=這個內容
⑵ 安卓Android開發,afinal中的FinalHttp如何獲取和設置cookie
1.獲取
finalHttp = new FinalHttp();
finalHttp.post(API.server, ajaxParams, new AjaxCallBack<String>() {
@Override public void onFailure(Throwable t, int errorNo, String strMsg) { super.onFailure(t, errorNo, strMsg);
closeProgressDialog();
prompt(getResources().getString(R.string.request_time_out));
System.out.println("errorNo:" + errorNo + ",strMsg:" + strMsg);
}
@Override public void onStart() { super.onStart();
showProgressDialog(getResources().getString(R.string.loading));
}
@Override public void onLoading(long count, long current) { super.onLoading(count, current);
}
@Override public void onSuccess(String t) { super.onSuccess(t); //從伺服器獲取CookieStore,保存到MyCookieStore
DefaultHttpClient client=(DefaultHttpClient)finalHttp.getHttpClient();
MyCookieStore.cookieStore = client.getCookieStore(); if (!StringUtils.isBlank(t)) {
Log.e(TAG, Constant.RESULT + API.GET_VERIFY_CODE + "
" + t.toString());
JSONStatus jsonStatus = BaseJSONData(t); if (jsonStatus.isSuccess) {
handler.sendMessage(handler.obtainMessage(GET_VERIFY_CODE_SUCCESS, BaseJSONData(t)));
} else {
handler.sendMessage(handler.obtainMessage(GET_VERIFY_CODE_FALSE, BaseJSONData(t)));
}
} else {
prompt(getResources().getString(R.string.request_no_data));
}
}
});
2.設置
OverridepublicvoidinitData() {finalHttp =newFinalHttp();//配置已保存的CookieStore,保證處於同一session中請求finalHttp.configCookieStore(MyCookieStore.cookieStore);finalHttp.post(API.server, ajaxParams,newAjaxCallBack<String>() {......(省略)}}
格式不行,湊合看吧
點贊+關注謝謝