"com.squareup.retrofit:改造:1.9.0"
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
へ
この依存関係を追加して完全ログを取得する
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'.
あなたのレトロフィットクライアントクラスのコードの下に
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.connectTimeout("Your_Time", TimeUnit.SECONDS);
httpClient.readTimeout("Your_Time", TimeUnit.SECONDS);
httpClient.addInterceptor(logging);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("BASE URL")
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
を、このメソッドを追加します
public Response post(String url, String content) throws IOException {
RequestBody body = RequestBody.create(PROTOCOL, content);
Request.Builder requestBuilder = new Request.Builder().url(url).post(body);
Request request = requestBuilder.build();
Response response = this.client.newCall(request).execute();
if(response.code() == 307) {
String location = response.header("Location");
return post(location, content);
}
return response;
}
改造APIを作成するためのコードを投稿してください。最新のバージョンのレトロフィットをリダイレクトをサポートしているokhttpで使ってみませんか? –
@lotfi reftrofitClientのセットアップ方法、また一般的なサービスを確認できますか? – Napster
Retrofit 1.9を使用する必要がある場合は、私の答えを見てください。さもなければ、私が見ているように自動的にリダイレクトを処理する2.0以上の方が簡単な方法だと思われます。 – mass