从okhttp请求中删除if-modified-since标头

时间:2015-01-29 09:21:18

标签: android http-headers okhttp

okhttp在请求中发送if-modified-since个日期和if-none-match校验和标头。通常不需要两者,if-none-match足以弄清楚客户端的版本。发送它们只会混淆一些http / 1.1服务器实现

我试过了

builder = new Request.Builder().removeHeader("if-modified-since");

但似乎没有这样做。我假设标题稍后添加。

有没有办法告诉okhttp不发送if-modified-since

1 个答案:

答案 0 :(得分:0)

是。你可以在建设者。 您基本上需要重建您的请求。这是一个完整的样本:

   httpClient.addInterceptor(new Interceptor() {
        @Override
        public okhttp3.Response intercept(Chain chain) throws IOException {
            Request newRequest = chain
                    .request()
                    .newBuilder()
                    .removeHeader("if-modified-since")
                    .build();
            return chain.proceed(newRequest);
        }
    });
相关问题