我正在尝试使用 Retrofit2
,我想将 Token
添加到我的 Header
像这样:
Authorization: Bearer Token
但下面的 code
不起作用:
public interface APIService {
@Headers({"Authorization", "Bearer "+ token})
@GET("api/Profiles/GetProfile?id={id}")
Call<UserProfile> getUser(@Path("id") String id);
}
我的服务器是 asp.net webApi
。请帮助我该怎么办?
原文由 farshad 发布,翻译遵循 CC BY-SA 4.0 许可协议
最好的方法是使用新的 Authenticator API。
参考: https ://square.github.io/okhttp/recipes/#handling-authentication-kt-java