xutils cookie获取和上传
Posted 巷子里的旧少年
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xutils cookie获取和上传相关的知识,希望对你有一定的参考价值。
public class MyCookieStore
public static CookieStore cookieStore=null;
获取cookieStore
String sessionID =null;
final HttpUtils http = new HttpUtils();
http.configCookieStore(MyCookieStore.cookieStore);
http.send(HttpRequest.HttpMethod.GET, groupInfoUrl,
new RequestCallBack<String>()
@Override
public void onSuccess(ResponseInfo<String> responseInfo)
dialog.dismiss();
//获取浏览器的session
DefaultHttpClient dh = (DefaultHttpClient) http.getHttpClient();
MyCookieStore.cookieStore = dh.getCookieStore();
CookieStore cs = dh.getCookieStore();
List<Cookie> cookies = cs.getCookies();
String aa = null;
for (int i = 0; i < cookies.size(); i++)
if ("JSESSIONID".equals(cookies.get(i).getName()))
aa = cookies.get(i).getValue();
break;
if (aa != null)
Log.d("jack", "比较sessionid" + aa.toString());
sessionID = aa.toString();
@Override
public void onFailure(HttpException error, String msg)
dialog.dismiss();
);
将获取到cookies添加到header中
params.addHeader("Cookie", "JSESSIONID=" + sessionID);
以上是关于xutils cookie获取和上传的主要内容,如果未能解决你的问题,请参考以下文章
Android使用xUtils3上传图片报错解决:java.lang.ArrayIndexOutOfBoundsException: 70918
xutils工具上传日志文件--使用https并且带进度条显示