【问题标题】:Alamofire cache issueAlamofire 缓存问题
【发布时间】:2017-12-12 02:05:23
【问题描述】:

我在使用 Alamofire 时遇到了问题,我对不同的请求得到了相同的响应。我使用以下方法请求:

        self.ephemeralManager?.request("myurladdress.com", headers: headers)
            .authenticate(user: username, password: password)
            .responseJSON { response in
                print(response)
            }

这里是会话管理器:

        let configuration = URLSessionConfiguration.ephemeral
        configuration.urlCache = nil
        ephemeralManager = Alamofire.SessionManager(configuration: configuration)

当我第一次发出请求时,它按预期工作。不久之后,当我使用不同的用户名和密码再次发出请求时,我会从上一个请求中获取响应数据。如果我重新启动应用程序或等待一段时间,请求会按预期工作。

我认为这是一个缓存问题,但在我发出请求或关闭缓存之前清除缓存的所有尝试都失败了。

我有什么遗漏的吗?我用过很多 Alamofire,从来没有遇到过这个问题。

Alamofire 版本:4.1 Xcode 版本:8.3.3 斯威夫特版本:3.1 运行 Alamofire 的平台:iOS 运行 Xcode 的 macOS 版本:10.12.5

【问题讨论】:

    标签: ios swift caching swift3 alamofire


    【解决方案1】:

    您可以在发出 alamofire 请求之前清除缓存。

    NSURLCache.sharedURLCache().removeAllCachedResponses()
    

    执行此命令后调用 alamofire 请求。

    【讨论】:

    • 它对我不起作用。我以前尝试过,但我又做了一次,没有运气。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 2011-08-12
    • 2012-05-20
    • 1970-01-01
    • 1970-01-01
    • 2020-11-04
    相关资源
    最近更新 更多