Android XUtils的cookie

// 访问登录的WebService

h = new HttpUtils();

h.send(HttpRequest.HttpMethod.POST, CDianApi.LOGIN, params,

new RequestCallBack<String>() {

@Override

public void onFailure(HttpException arg0, String arg1) {

}

@Override

public void onSuccess(ResponseInfo<String> data) {

// Cookie

DefaultHttpClient dh = (DefaultHttpClient) h.getHttpClient();

// 自定义类 静态变量存储

AaCookieStore.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;

}

}

}

});

// 自定义存储类

public class AaCookieStore {

public static CookieStore cookieStore = null;

}

再访问WebService的时候

hu = new HttpUtils();

hu.configCookieStore(CDianCookieStore.cookieStore);

hu.send(HttpRequest.HttpMethod.GET,..................................


你可能感兴趣的:(android,cookie)