Retrofit add header with token and id

前端 未结 2 1456
醉梦人生
醉梦人生 2021-02-04 17:14

I have a problem with getting authenticated user. Before it I got token and user id. Now i need to get user from server using access token and id. I have header format

相关标签:
2条回答
  • 2021-02-04 17:32

    Try to pass the header values via the method call:

    @GET("driver/v1/driver")
    Call<Driver> getAuthorizedDriver(@Header("authorization") String token,
                                     @Header("driver_id") Integer id);
    

    You also wouldn't have to deal with this huge chunk of Interceptor code

    0 讨论(0)
  • 2021-02-04 17:54

    I got it. It's must look like:

    @GET("driver/v1/driver")
    Call<Driver> getAuthorizedDriver(@Header("authorization") String auth);
    

    And auth:

    Call<Driver> call = apiInterface.getAuthorizedDriver("Token token=" + token + ", driver_id=" + id);
    
    0 讨论(0)
提交回复
热议问题