我使用我的应用程序中的 OkHttpClient (v3.0.1),但 ETag 和 If-None-Match 不起作用。</p>
例如:
首先 获取http://112.4.19.67/task/imags_avatar/20130607165126605.png
作为回应,我得到了 ETag 和 Last-Modified。
要求:</p>
GET /task/imags_avatar/20130607165126605.png HTTP/1.1
Host: 112.4.19.67
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: okhttp/3.0.1
回应:</p>
HTTP/1.1 200 OK
Server: Apache
Last-Modified: Mon, 30 Jun 2014 04:44:43 GMT
ETag: "1205-4fd06515d9572"
Content-Type: image/png
Content-Length: 4613
Accept-Ranges: bytes
Date: Thu, 04 Feb 2016 13:30:05 GMT
X-Varnish: 3684240013 3683622711
Age: 1313
Via: 1.1 varnish
Connection: keep-alive
第二次 获取相同的网址:http: //112.4.19.67/task/imags_avatar/20130607165126605.png
我认为我可以看到请求中的 If-None-Match。但它不存在。
要求:</p>
GET /task/imags_avatar/20130607165126605.png HTTP/1.1
Host: 112.4.19.67
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: okhttp/3.0.1
回复:
HTTP/1.1 200 OK
Server: Apache
Last-Modified: Mon, 30 Jun 2014 04:44:43 GMT
ETag: "1205-4fd06515504c0"
Content-Type: image/png
Content-Length: 4613
Accept-Ranges: bytes
Date: Thu, 04 Feb 2016 13:30:26 GMT
X-Varnish: 3389168698 3388862573
Age: 642
Via: 1.1 varnish
Connection: keep-alive
我的代码
File file = getCacheDir();
Cache cache = new Cache(file, CACHE_SIZE);
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.cache(cache);
OkHttpClient client = builder.build();
Request request = new Request.Builder()
.url(url)
.build();
提前感谢您的帮助。