Exclude default headers set by OkHttp library

点点圈 提交于 2019-12-02 04:17:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!