ios – Alamofire自动存储cookies?

前端之家收集整理的这篇文章主要介绍了ios – Alamofire自动存储cookies?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是新的Alamofire,所以我很抱歉,如果这是一个noob问题:这个框架自动存储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 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.

原文链接:https://www.f2er.com/iOS/337062.html

猜你在找的iOS相关文章