【问题标题】:Remove if-modified-since header from okhttp request从 okhttp 请求中删除 if-modified-since 标头
【发布时间】:2015-03-28 10:58:49
【问题描述】:

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

【问题讨论】:

标签: android http-headers okhttp


【解决方案1】:

是的。你可以在生成器中。 您基本上需要重建您的请求。这是一个完整的示例:

   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);
        }
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-27
    • 2012-10-01
    • 2012-11-01
    • 2015-11-24
    • 1970-01-01
    • 2016-12-10
    • 2016-04-02
    • 2011-07-02
    相关资源
    最近更新 更多