无法使用翻新设置标题

时间:2018-09-08 07:37:23

标签: java android http-headers retrofit2

我正在尝试设置标题

public static Retrofit getClientWithHeader(String baseUrl) {

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder()
                .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));


        httpClient.addInterceptor(new Interceptor() {
            @Override
            public okhttp3.Response intercept(Chain chain) throws IOException {
                Request original = chain.request();


                Request request = original.newBuilder()
                        .header(GlobalEnum.PREFS_OAUTH_KEY,"Bearer " + DataManager.getAccessToken(HULApp.getInstance()))
                        .build();

                return chain.proceed(request);


            }
        });

        client = httpClient.build();

        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .client(client)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();

        }
        return retrofit;
    }

但是当我在服务器上检查时,API调用未收到标头。 我试图通过设置断点来调试代码,但是它没有进入标头拦截器中。

0 个答案:

没有答案