问题
In recent versions of OkHttp library, headers like "Accept-Encoding" and "User-Agent" are added automatically if you don't provide them by yourself.
Is there a way to disable this feature?
回答1:
Strip 'em with a Network Interceptor.
client.networkInterceptors().add(new Interceptor() {
@Override public Response intercept(Chain chain) throws IOException {
Request request = chain.request()
.newBuilder()
.removeHeader("Accept-Encoding")
.removeHeader("User-Agent")
.build();
return chain.proceed(request);
}
});
来源:https://stackoverflow.com/questions/32289189/exclude-default-headers-set-by-okhttp-library