cookie
来源:互联网 发布:知乎话题广场 编辑:程序博客网 时间:2024/06/06 16:36
public static void sendPost(final Context context, RequestParams params, final boolean isSaveCookie, final UtilHttpListenerInterface listener) { /*取cookie*/ String value = context.getSharedPreferences("SP_NAME",Context.MODE_PRIVATE).getString("value",""); String domain = context.getSharedPreferences("SP_NAME",Context.MODE_PRIVATE).getString("domain",""); String path = context.getSharedPreferences("SP_NAME",Context.MODE_PRIVATE).getString("path",""); if (!value.equals("")){ strCookie.append(String.format("SHAREJSESSIONID=%s", value)); strCookie.append(String.format(";domain=%s", domain)); strCookie.append(String.format(";path=%s",path)); /*传cookie*/ params.addHeader("Cookie", strCookie.toString()); } x.http().post(params, new Callback.CommonCallback<String>() { @Override public void onCancelled(CancelledException arg0) { } @Override public void onError(Throwable ex, boolean isOnCallback) { if (ex instanceof HttpException) { // 网络错误 HttpException httpException = (HttpException) ex; listener.onFailed(httpException.getCode(), httpException.getMessage(), httpException.getResult()); } else { // 其他错误 } } // 不管成功或者失败最后都会回调该接口 @Override public void onFinished() { } @Override public void onSuccess(String result) { if (isSaveCookie) { /*取cookie*/ DbCookieStore instance = DbCookieStore.INSTANCE; List<HttpCookie> cookies = instance.getCookies(); for (int i = 0; i < cookies.size(); i++) { HttpCookie cookie = cookies.get(i); String name = cookie.getName(); String value = cookie.getValue(); String domain = cookie.getDomain(); String path = cookie.getPath(); Log.d("aaa",name+value); if (name.equals("JSESSIONID")){ /*存cookie*/ SharedPreferences.Editor editor = context.getSharedPreferences("SP_NAME", context.MODE_PRIVATE).edit(); editor.putString("value", value); editor.putString("domain", domain); editor.putString("path", path); editor.commit(); } ; sbCookie.append(String.format("SHAREJSESSIONID=%s", cookie.getValue())); sbCookie.append(String.format(";domain=%s", cookie.getDomain())); sbCookie.append(String.format(";path=%s", cookie.getPath())); String cookieValue = sbCookie.toString(); } } listener.onSucceed(result); } });}
0 0
- Cookie
- cookie
- cookie
- Cookie
- cookie
- Cookie
- cookie
- Cookie
- Cookie
- Cookie
- cookie
- cookie
- cookie
- Cookie
- cookie
- Cookie
- cookie
- cookie
- Yii框架CDbCommand使用感悟
- Python中list相关操作
- 一些常见的重置密码漏洞分析整理
- Ajax模式List页面支持JS,JS支持页面分页的AjaxList.js
- Binder源码分析之Java层
- cookie
- (iOS开发)点击tabbar中的按钮显示首页,再如何跳转页面
- android让后将程序图标显示在状态栏
- Javascript 赋值与比较
- go语言学习道路(插曲)-一个疑惑的问题
- C++模板中的函数式参数
- 电机驱动电路
- stringbuffer与stringbuilder的区别?
- SpringMVC 的 Controller 返回各种视图的处理方式