gpt4 book ai didi

iphone - NSURLConnection、NSURLRequest 和远程缓存

转载 作者:可可西里 更新时间:2023-11-01 15:13:00 25 4
gpt4 key购买 nike

我在 iPhone 上使用 NSURLConnection 异步连接进行请求缓存时遇到了一个小问题。我不知道是不是我理解有误,还是 Cocoa 做的与它应该做的相反......

NSURLRequest 的文档说:

NSURLRequestReloadIgnoringLocalCacheData

Specifies that the data for the URL load should be loaded from the originating source. No existing cache data should be used to satisfy a URL load request.

和:

NSURLRequestReloadIgnoringLocalAndRemoteCacheData

Specifies that not only should the local cache data be ignored, but that proxies and other intermediates should be instructed to disregard their caches so far as the protocol allows.

现在,如果我发送带有 NSURLRequestReloadIgnoringLocalCacheData 的 NSURLRequest(应该忽略本地缓存,但如果可用则使用远程缓存),发送的 header 是:

GET /dashboard HTTP/1.1User-Agent: XBlip1.0 CFNetwork/422.15.2 Darwin/9.6.0 (i386) (iMac8%2C1)X-Blip-Api: 0.02Accept: application/jsonAuthorization: Basic (...)Accept-Language: en-usAccept-Encoding: gzip, deflateConnection: keep-aliveHost: api.blip.pl

状态为 200 OK。但是,如果我使用 NSURLRequestReloadIgnoringLocalAndRemoteCacheData,顾名思义,它应该忽略本地和远程缓存,则会添加一个额外的 header :

If-None-Match: "d751713988987e9331980363e24189ce"

响应是 304 Not Modified。我检查了 HTTP RFC,对于“If-None-Match”,它说:

If any of the entity tags match the entity tag of the entity that would have been returned in the response to a similar GET request (without the If-None-Match header) on that resource, (...) then the server MUST NOT perform the requested method (...) Instead, if the request method was GET or HEAD, the server SHOULD respond with a 304 (Not Modified) response

所以看起来如果我使用 NSURLRequestReloadIgnoringLocalAndRemoteCacheData,而不是忽略远程缓存,Cocoa 明确地告诉远程服务器它应该使用远程缓存,如果我使用 NSURLRequestReloadIgnoringLocalCacheData,它不会添加该行实际上未使用远程缓存。

那么这里到底发生了什么?我错过了什么,还是 Cocoa 设置了错误的 header ?

最佳答案

来自文档:

Specifies that not only should the local cache data be ignored, but that proxies and other intermediates should be instructed to disregard their caches so far as the protocol allows.

来自 NSURLRequest.h (10.5 SDK)

Specifies that not only should the local cache data be ignored, but that proxies and other intermediates should be instructed to disregard their caches so far as the protocol allows. Unimplemented.

注意区别:未实现

错误报告时间...

关于iphone - NSURLConnection、NSURLRequest 和远程缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/670056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com