我在使用 Alamofire 时遇到了一个问题,我对不同的请求得到了相同的响应。我使用以下方法请求:
self.ephemeralManager?.request("myurladdress.com", headers: headers)
.authenticate(user: username, password: password)
.responseJSON { response in
print(response)
}
这是 session 管理器:
let configuration = URLSessionConfiguration.ephemeral
configuration.urlCache = nil
ephemeralManager = Alamofire.SessionManager(configuration: configuration)
当我第一次发出请求时,它按预期工作。不久之后,当我使用不同的用户名和密码再次发出请求时,我从上一个请求中获得了响应数据。如果我重新启动应用程序或等待一段时间,请求会按预期工作。
我假设这是一个缓存问题,但在我发出请求之前清除缓存或关闭缓存的所有尝试都失败了。
有什么我想念的吗?我经常使用 Alamofire,从未遇到过这个问题。
Alamofire 版本:4.1 Xcode 版本:8.3.3 swift 版本:3.1 运行 Alamofire 的平台:iOS 运行 Xcode 的 macOS 版本:10.12.5
最佳答案
您可以在发出 alamofire 请求之前清除缓存。
NSURLCache.sharedURLCache().removeAllCachedResponses()
执行此命令后调用 alamofire 请求。
关于ios - Alamofire 缓存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44976454/