Alamofire会自动存储cookie吗? [英] Does Alamofire store the cookies automatically?

查看:165
本文介绍了Alamofire会自动存储cookie吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Alamofire 的新手,所以如果这是一个noob问题我很抱歉:此框架会自动存储Cookie

I'm new to Alamofire so I'm sorry if this it's a noob question: this framework store automatically the cookies?

这是因为我有这样一个简单的请求:

This is because I have a simple request like this:

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会话,因为他们在postman上失败,例如但不在这里。

this request response with a cookie session that I need to do other requests for security reason; the strange thing is that like magic I already can do the other requests after this first POST without read manually the cookie and store it. I'm sure the other requests need the cookie session because they fail on postman for example but not here.

这只是一个功能?因为我在官方的 GitHub页面上找不到任何内容。

It's just a feature? Because I can't find anything on that also on the official GitHub page.

推荐答案

是的! Alamofire基本上是 NSURLSession 的包装器。它的管理器通过调用 defaultSessionConfiguration()来使用默认的 NSURLSessionConfiguration

Yes! Alamofire is basically a wrapper around NSURLSession. Its manager uses a default NSURLSessionConfiguration by calling defaultSessionConfiguration().

正如其github页面在 高级用法 部分:

As its github page says under Advanced Usage section:


Alamofire建立在 NSURLSession 和基础URL加载系统之上。为了充分利用这个框架,建议您熟悉底层网络堆栈的概念和功能。

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.

经理 部分下:


Alamofire.request等顶级便利方法使用Alamofire.Manager的共享实例,该实例配置为默认NSURLSessionConfiguration

defaultSessionConfiguration()的occ / clm / NSURLSessionConfiguration / defaultSessionConfiguration> NSURLSessionConfiguration reference 说:

And the NSURLSessionConfiguration reference for defaultSessionConfiguration() says:


默认会话配置使用基于磁盘的持久缓存(除非将结果下载到文件中)和stor es用户钥匙串中的凭据。它还将Cookie (默认情况下)存储在与NSURLConnection和NSURLDownload类相同的共享Cookie存储区中。

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.

这篇关于Alamofire会自动存储cookie吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆