/api/method?page=1.json
のようなエンドポイントを生成したいのですが、最後に/api/method.json?page=1
のようにクエリが挿入されるという問題があります。Retrofit - クエリを挿入した後にエンドポイントの末尾にテキストを追加
// from my service
@GET("method.json")
Call<Void> method(@Query("page") int page);
// building retrofit
new Retrofit.Builder()
.baseUrl(URL)
.client(httpClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
更新/続い作品が、私は答える@Blackbeltは最高の一つです。あなたが好きなものを使用することができます
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BASIC : HttpLoggingInterceptor.Level.NONE);
return new OkHttpClient.Builder()
.addInterceptor(logging)
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
request = request.newBuilder().url(request.url().toString().concat(".json")).build();
return chain.proceed(request);
}
})
.build();
これは私が考える醜い解決策です。私がこれをやっている理由は、結果をJSONとして返すCakePHPが原因です。別の解決策がありますか?コールバックの内部を使用する前にURLを変更することは可能ですか? – Alireza
あなたはインターセプターを使うことができますが、私はそれを避けてシンプルにしていきます。 – Blackbelt
この場合、インターセプターを私に教えてもらえますか? – Alireza