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.

以上是来客网为你收集整理的ios – Alamofire自动存储cookies?全部内容,希望文章能够帮你解决ios – Alamofire自动存储cookies?所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。