首页 > 学院 > 开发设计 > 正文

AsyncHttpClient 维持登录状态

2019-11-08 02:55:11
字体:
来源:转载
供稿:网友
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();


上一篇:USACO 2.1.1 Castle

下一篇:一元多项式相乘

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表