Hey, As per the doc I tried setting Headers through request interceptors first. Below is the snippet
OkHttpClient httpClient = new OkHttpClient.Builder()
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request requestWithHeader = request.newBuilder().header("Authorization",RequestInterceptor.authToken)
.header("Content-Type","application/json")
.method(request.method(),request.body())
.build();
return chain.proceed(requestWithHeader);
}
}).addNetworkInterceptor(httpLoggingInterceptor)
.build();
When i checked the logs, content-type is missing.
Code snippet:
@GET("/categories/")
Call<Result> getCategory(@Header("Content-Type") String header);
//Invocation part:
Call
OkHttp removes the content type when the request method (in this case GET) does not support a body: https://github.com/square/okhttp/blob/6014ab9752cff344a0baf57eb7626d98ca1d3401/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.java#L317. Retrofit does not control this behavior since it's deep inside OkHttp, but I agree with it. A Content-Type header makes no sense when there's no actual request body with content.
Most helpful comment
OkHttp removes the content type when the request method (in this case
GET) does not support a body: https://github.com/square/okhttp/blob/6014ab9752cff344a0baf57eb7626d98ca1d3401/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.java#L317. Retrofit does not control this behavior since it's deep inside OkHttp, but I agree with it. AContent-Typeheader makes no sense when there's no actual request body with content.