【问题标题】:Retrofit: cache-control never included in response改造:缓存控制从未包含在响应中
【发布时间】:2014-06-28 13:44:10
【问题描述】:

无论我做什么,我都无法在响应中看到标头 cache-control

设置

  • 改造 1.6.0
  • okHttp 1.6.0
  • okHttp-urlConnection 1.6.0
  • gson 2.2.4
  • Android 4.0+

1.配置

1.1 RestAdapter 和我的 OkHttpClient

OkHttpClient okHttpClient = new OkHttpClient();
Cache cache = new Cache(getCacheDir(), 1024);
okHttpClient.setCache(cache);

RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(URL)
            .setClient(new OkClient(okHttpClient))
            .setLogLevel(LogLevel.HEADERS)
            .build();

1.2 带有默认 OkHttpClient 的 RestAdapter 在这里,调试时我可以看到客户端有 cache=null;

RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(URL)
            .setLogLevel(LogLevel.HEADERS)
            .build();

2 条日志

对于这两种配置,日志是相同的。

2.1 请求

06-28 13:24:05.601: D/Retrofit(1581): ---> HTTP GET myUri

06-28 13:24:05.601:D/Retrofit(1581):缓存控制:公共, 最大年龄=640000

06-28 13:24:05.601: D/Retrofit(1581): ---> END HTTP(无正文)

2.2 回应

06-28 13:24:05.701: D/Retrofit(1581):

06-28 13:24:05.701: D/Retrofit(1581): : HTTP/1.1 200 OK

06-28 13:24:05.701:D/Retrofit(1581):连接:保持活动

06-28 13:24:05.701: D/Retrofit(1581): Content-Type: text/html

06-28 13:24:05.701:D/Retrofit(1581):日期:2014 年 6 月 28 日星期六 13:24:01 格林威治标准时间

06-28 13:24:05.701: D/Retrofit(1581): OkHttp-Received-Millis: 1403961845708

06-28 13:24:05.701: D/Retrofit(1581): OkHttp-Response-Source: NETWORK 200

06-28 13:24:05.701: D/Retrofit(1581): OkHttp-Sent-Millis: 1403961845680

06-28 13:24:05.701:D/Retrofit(1581):服务器:nginx/1.6.0

06-28 13:24:05.701:D/Retrofit(1581):传输编码:分块

06-28 13:24:05.701:D/Retrofit(1581):变化:接受编码

06-28 13:24:05.701: D/Retrofit(1581): X-Powered-By: PHP/5.5.12-1~dotdeb.1

06-28 13:24:05.701: D/Retrofit(1581):

编辑 03/07/2014

我注意到在这个问题Retrofit+OkHttp is ok when sending GET requests but gives SocketTimetout when sending POST 中,提问者得到“缓存控制”作为响应。

04-11 18:00:41.291: D/Retrofit(16390): ---> HTTP GET url

04-11 18:00:41.291: D/Retrofit(16390): ---> END HTTP(0 字节正文)

04-11 18:00:42.008: D/Retrofit(16390):

04-11 18:00:42.015: D/Retrofit(16390): : HTTP/1.1 200 OK

04-11 18:00:42.015: D/Retrofit(16390): Cache-Control: max-age=0, private, must-revalidate

在模拟器和真实设备中仍然无法解决这个问题......

【问题讨论】:

    标签: android rest retrofit


    【解决方案1】:

    我的笨蛋,我们没有在后端正确设置缓存!

    【讨论】:

      猜你喜欢
      • 2017-05-09
      • 2017-04-29
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-18
      • 1970-01-01
      相关资源
      最近更新 更多