多个NSHTTPCookieStorage在同一个应用程序 [英] Multiple NSHTTPCookieStorage in the same app

查看:207
本文介绍了多个NSHTTPCookieStorage在同一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 NSURLSession 编写一个多用户应用程序,我不知道如何使用多个 NSURLSession 实例。



我尝试设置 NSURLSessionConfiguration HTTPCookieStorage 属性与一个 NSHTTPCookieStorage 我分配/ init'ed自己,但它不工作(cookie不存储,即使我调用 setCookie:自己)



我也尝试使用 [NSURLSessionConfiguration ephemeralSessionConfiguration] 但再次,我的cookie不存储在请求之间。 Set-Cookie 头出现在服务器的响应中,并使用 [NSHTTPCookieStorage sharedHTTPCookieStorage]



是否可以为不同的 NSURLSession 实例分别存储cookie存储?我相信这是新的网络API的主要点之一。

解决方案

我试图实现同样的事情。 / p>

ephemeralSessionConfiguration不会存储您的Cookie,因为它的cookieAcceptPolicy总是设置为NEVER,即使您尝试将其更改为其他。对于手动分配的NSURLSessionConfiguration也是如此。



从我的观点来看,这与暂时会话使用内存中的cookie存储的文档形成对比。 p>

我已经针对这个问题发布了一个单独的问题:
如何为临时NSURLSession设置cookieAcceptPolicy


I am writing a multi-user app using NSURLSession and I can't figure out how to have a separate cookie storage when working with multiple NSURLSession instances.

I tried setting NSURLSessionConfiguration's HTTPCookieStorage property with a NSHTTPCookieStorage that I alloc/init'ed myself but it doesn't work (cookies aren't stored, even if I call setCookie: myself)

I also tried using [NSURLSessionConfiguration ephemeralSessionConfiguration] but then again, my cookies aren't stored between requests. The Set-Cookie header is present in the server's responses, and using [NSHTTPCookieStorage sharedHTTPCookieStorage] works so the issue is in the code.

Is it at all possible to have separate cookie stores for different NSURLSession instances? I believed it was one of the main point of the new networking API.

解决方案

I am trying to achieve the same thing.

The ephemeralSessionConfiguration doesn't store your cookies, because its cookieAcceptPolicy is always set to NEVER, even if you try to change it to something else. Same goes for the manually allocated NSURLSessionConfiguration.

From my point of view this is in contrast to the documentation which states that ephemeral sessions use an in-memory cookie store.

I have posted a separate question regarding this issue: How to set cookieAcceptPolicy for ephemeral NSURLSession

这篇关于多个NSHTTPCookieStorage在同一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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