AsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder()
.addResponseFilter(new ResponseFilter() {
@Override
public <T> FilterContext<T> filter(FilterContext<T> ctx) throws FilterException {
String c = ctx.getResponseHeaders().getHeaders().get("Set-Cookie");
if (!TextUtils.isEmpty(c)) {
cookie = c;
System.out.println(cookie);
}
return ctx;
}
})
.build();
AsyncHttpClient client = new DefaultAsyncHttpClient(config);
配置的时候,拿到Set-Cookie请求头。只有登录的时候会有这个请求头。然后其他请求时,加上Cookie请求头
Response response = client
.preparePost("")
.addHeader("Cookie", cookie)
.execute().get();