okhttpフレームワーク取得sessionid操作

1359 ワード

OkHttpUtils .get() .url(Constant.HTTP_URL + "login") .addParams("username", mLoginAccount) .addParams("password", mLoginPassword) .build() .execute(new StringCallback() { @Override public void onError(Call call, Exception e, int id) { }
                @Override
                public void onResponse(String response, int id) {
                    handleData(response);
                }

                @Override
                public String parseNetworkResponse(Response response, int id) throws IOException {
                    // session ,session cookie , “;”,  s ( jsesseionid)
                    Headers headers = response.headers();
                    Log.e(TAG, "header " + headers);
                    List cookies = headers.values("Set-Cookie");
                    String session = cookies.get(0);
                    Log.e(TAG, "onResponse-size: " + cookies);
                    String s = session.substring(0, session.indexOf(";"));
                    Log.e(TAG, "session is :" + s);
                    return super.parseNetworkResponse(response, id);
                }
            });

使用時:OkHttpUtils.post() .url(Constant.HTTP_URL + "query") .addHeader("cookie", s)) .build() .execute(new StringCallback() {