"com.squareup.retrofit: güçlendirme: 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'
için
da, tüm günlüğü almak için bu bağımlılığı ekleyin
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'.
Kodun altında
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();
Http protokolü istisna HttpLoggingInterceptor
koymak ve günlükleri kontrol etmek
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;
}
Güçlendirme api oluşturma kodunu kaydedin. Sadece bilgi için neden yeniden yönlendirme için daha fazla desteğe sahip okhttp ile retrofit'in son sürümünü kullanmıyorsunuz? –
@lotfi reftrofitClient kurulum yönteminizi, ayrıca ortak hizmeti görebilir miyim. – Napster
Retrofit 1.9'u kullanmanız gerekiyorsa, cevabımıma bakın. Aksi halde gördüğüm gibi otomatik olarak 307 üzerinde yönlendirme işleyen 2.0+ ile gitmek için daha kolay bir yol gibi görünüyor. – mass