我正在爲網絡調用創建一個帶retrofit2的應用程序。我需要在單個活動中調用多個API。現在我面臨着403-禁止的錯誤。如果我只打一個API,它工作正常。但是如果我一個一個地使用多個API調用,那麼我正面臨着這個錯誤。Android - Retrofit2 - 403-Forbidden
我的CreateService方法如下:
public static <S> S createService(Class<S> serviceClass, final String authToken) {
if (authToken != null) {
httpClient.addInterceptor(new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();
// Request customization: add request headers
Request.Builder requestBuilder = original.newBuilder()
.header("Authorization-Token", authToken)
.method(original.method(), original.body());
Request request = requestBuilder.build();
return chain.proceed(request);
}
});
}
// OkHttpClient client = httpClient.readTimeout(60, TimeUnit.SECONDS).connectTimeout(60, TimeUnit.SECONDS).build();
Dispatcher dispatcher = new Dispatcher(Executors.newFixedThreadPool(200));
dispatcher.setMaxRequests(200);
dispatcher.setMaxRequestsPerHost(1);
OkHttpClient okHttpClient = httpClient.dispatcher(dispatcher).connectionPool(new ConnectionPool(100, 30, TimeUnit.SECONDS)).build();
Retrofit retrofit = builder.client(okHttpClient).build();
return retrofit.create(serviceClass);
}
有什麼錯我的代碼..我如何處理呢?
是那裏等待第一個API調用拉開了第二屆一個之前完成任何依賴性? –
沒有所有的API都有不同的數據。沒有關係 – Amsheer