我是新来的阿拉莫菲尔所以我很抱歉,如果这是一个菜鸟问题:该框架自动存储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 会话,出于安全原因我需要执行其他请求;奇怪的是,就像魔术一样,我已经可以在第一个 POST 之后执行其他请求,而无需手动读取 cookie 并存储它。我确信其他请求需要 cookie 会话,因为它们在邮递员上失败,但在此处失败。
这只是一个功能吗?因为我在官方也找不到任何相关内容GitHub 页面 https://github.com/Alamofire/Alamofire.
是的! Alamofire 基本上是一个包装器NSURLSession
。它的管理器使用默认值NSURLSessionConfiguration
通过致电defaultSessionConfiguration()
.
正如其 github 页面所示高级用法 https://github.com/Alamofire/Alamofire#advanced-usage部分:
Alamofire 构建于NSURL会话和基础 URL 加载系统。为了充分利用此框架,建议您熟悉底层网络堆栈的概念和功能。
并在下面Manager https://github.com/Alamofire/Alamofire#manager部分:
像 Alamofire.request 这样的顶级便捷方法使用 Alamofire.Manager 的共享实例,该实例配置有默认 NSURLSessionConfiguration.
And the NSURLSession配置参考 https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSessionConfiguration_class/index.html#//apple_ref/occ/clm/NSURLSessionConfiguration/defaultSessionConfiguration for defaultSessionConfiguration()
says:
默认会话配置使用基于磁盘的持久缓存(除非将结果下载到文件中)并将凭据存储在用户的钥匙串中。它也是存储cookie(默认情况下)与 NSURLConnection 和 NSURLDownload 类位于同一共享 cookie 存储中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)