排除OkHttp库设置的默认标头 [英] Exclude default headers set by OkHttp library
本文介绍了排除OkHttp库设置的默认标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在最新版本的OkHttp库中,如果您自己不提供标题,则会自动添加诸如"Accept-Encoding"和"User-Agent"之类的标题.
In recent versions of OkHttp library, headers like "Accept-Encoding" and "User-Agent" are added automatically if you don't provide them by yourself.
是否可以禁用此功能?
推荐答案
使用网络对它们进行剥离拦截器.
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);
}
});
这篇关于排除OkHttp库设置的默认标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文