ios - Alamofire 会自动存储 cookie 吗?

标签 ios swift post cookies alamofire

我是 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/

相关文章:

ios - 将数组数据显示在一个字典中?

swift - UITextView 长度问题

post - cURL 有效,但没有其他客户端使用 Go sebserver

ios - POST API 调用在处理 JSON 正文时遇到问题

iphone - 您可以在 iPhone 的文档文件夹中添加默认文档吗

ios - `tableView.dequeueReusableCell(withIdentifier:for:)` 从父类调用初始化器

iphone - 如何在单击按钮时立即更改 UINavigationBar 图像?

ios - iOS Playground do 方法中的 Json 解析未解析

arrays - Swift 谓词只匹配值数组中的第一个值

xml - 需要从页面中提取 XML,然后放入 HTML 格式。页面由 POST 方法生成