我是 Alamofire 的新手,如果这是一个菜鸟问题,我很抱歉:这个框架会自动存储 cookie?
这是因为我有一个像这样的简单请求:
Alamofire.request(.POST, loginURL, parameters: ["fb_id": fbId, "fb_access_token": fbToken])
.responseJSON { response in
//print(response.request) // original URL request
//print(response.response) // URL response
//print(response.data) // server data
//print(response.result) // result of response serialization
if let JSON = response.result.value {
print("loginURL - JSON: \(JSON)")
}
}
此请求响应带有 cookie session ,出于安全原因我需要执行其他请求;奇怪的是,就像魔术一样,我已经可以在第一次 POST 之后执行其他请求,而无需手动读取 cookie 并存储它。我确定其他请求需要 cookie session ,因为它们在 postman 上失败了,但在这里没有。
这只是一个功能?因为我在官方GitHub page上也找不到任何东西.
最佳答案
是的! Alamofire 基本上是 NSURLSession
的包装器。它的管理器通过调用 defaultSessionConfiguration()
使用默认的 NSURLSessionConfiguration
。
正如它的 github 页面在 Advanced Usage 下所说的那样部分:
Alamofire is built on NSURLSession and the Foundation URL Loading System. To make the most of this framework, it is recommended that you be familiar with the concepts and capabilities of the underlying networking stack.
在Manager下部分:
Top-level convenience methods like Alamofire.request use a shared instance of Alamofire.Manager, which is configured with the default NSURLSessionConfiguration.
还有 NSURLSessionConfiguration reference对于 defaultSessionConfiguration()
说:
The default session configuration uses a persistent disk-based cache (except when the result is downloaded to a file) and stores credentials in the user’s keychain. It also stores cookies (by default) in the same shared cookie store as the NSURLConnection and NSURLDownload classes.
关于ios - Alamofire 会自动存储 cookie 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35025110/