【问题标题】:Android: How to get session id using Retrofit?Android:如何使用 Retrofit 获取会话 ID?
【发布时间】:2017-09-04 00:57:00
【问题描述】:

我想从登录面板获取会话 ID,我正在使用 Retrofit 发出请求。

但是在响应中查找标题时,我没有找到任何 cookie 集

这里是请求代码:

Retrofit retrofit = new Retrofit.Builder().baseUrl(getResources().getString(R.string.baseurl)).addConverterFactory(GsonConverterFactory.create(gson)).build();
API api = retrofit.create(API.class);

Call<ResponseBody> call = api.loginhtml(et_user.getText().toString(), et_pass.getText().toString());
call.enqueue(new Callback<ResponseBody>() {
    @Override
    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
        try {
            String head = String.valueOf(response.headers());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onFailure(Call<ResponseBody> call, Throwable t) {

    }
});

【问题讨论】:

    标签: android retrofit retrofit2


    【解决方案1】:

    通过使用此代码,您可以进行会话

    response.headers().get("Set-Cookie")
    

    【讨论】:

      猜你喜欢
      • 2012-02-02
      • 2022-11-08
      • 2011-10-27
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 2022-10-02
      • 2017-12-21
      相关资源
      最近更新 更多