次の2つの選択肢を持っている - あなたはあなたの呼び出しにパラメータとして追加することができます - あなたは呼び出しごとに"Bearer" + token
に合格する必要がありますので
@GET("api/Profiles/GetProfile?id={id}")
Call<UserProfile> getUser(@Path("id") String id, @Header("Authorization") String authHeader);
これは少しいらいらすることができます。これは、トークンを必要とするコールがあまりない場合に適しています。
あなたはすべての要求にヘッダを追加したい場合は、あなたがokhttpインターセプターを使用することができます - 「トークン」
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request newRequest = chain.request().newBuilder()
.addHeader("Authorization", "Bearer " + token)
.build();
return chain.proceed(newRequest);
}
}).build();
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(/** your url **/)
.addConverterFactory(GsonConverterFactory.create())
.build();
をヘッダのみを追加するこの方法が機能するには、コンパイル時定数です。 Javaのアノテーション規則など。 documetationはヘッダをインクルードする別の方法を提供しています:http://square.github.io/retrofit/(メソッドのパラメータにします) – zapl