需要在Android改装中实现基本身份验证以及参数

时间:2019-02-01 07:26:26

标签: authentication retrofit

我正在使用以下代码添加包含基本身份验证的标头。

    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    httpClient.addInterceptor(interceptor);

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

            Request authenticatedRequest = original.newBuilder()
                    .addHeader("Accept", "application/json")
                    .addHeader("Content-Type", "application/json")
                    .addHeader("Authorization", Credentials.basic("admin", "admin")).build();

            return chain.proceed(authenticatedRequest);
        }
    });

    okHttpClient = httpClient.build();

这是我的请求参数。

@FormUrlEncoded
@POST("getdata/")
Call<ResponseData> getResponseData(
        @Field("PGEO_CNTRY_ID") String PGEO_CNTRY_ID,
        @Field("PAPPL_ID") String PAPPL_ID,
        @Field("PUSER_ID") String PUSER_ID
);

我收到不受支持的媒体类型错误。

0 个答案:

没有答案