【问题标题】:AFHTTPSessionManager with Cache Policy not working带有缓存策略的 AFHTTPSessionManager 不起作用
【发布时间】:2015-08-18 13:26:26
【问题描述】:

服务器发送缓存头作为响应。

"Cache-Control": "max-age=120, public"

首先我将 NSURLRequestReturnCacheDataElseLoad 与 AFHTTPRequestOperation 一起使用。

通过在 AppDelegate 中设置共享缓存并在 NSUrlRequest 中设置 NSURLRequestReturnCacheDataElseLoad。

效果很好。

但是当我尝试通过以下方式设置 NSURLRequestReturnCacheDataElseLoad 对 AFHTTPSessionManager 执行相同操作时,

1.request.session.configuration.requestCachePolicy

2.request.requestSerializer.cachePolicy

3.重写-(NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLResponse *, id, NSError *))completionHandler

似乎没有任何效果。

AFNetworking 版本 - 2.5.1

【问题讨论】:

  • 哪个版本的afnetworking?
  • afnetworking 2.5.1版

标签: ios afnetworking-2 nsurlrequestcachepolicy


【解决方案1】:

我遇到了同样的问题,经过几个小时的搜索,我发现 AFHTTPSessionManager 使用 cookie 来缓存请求。

只需删除所有 cookie 即可。

NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (NSHTTPCookie *cookie in [storage cookies]) {
        [storage deleteCookie:cookie];
    }

【讨论】:

    猜你喜欢
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    • 2010-10-06
    • 2013-03-30
    相关资源
    最近更新 更多