问题描述
我使用
是否可以为不同的 NSURLSession 实例分别存储cookie存储?我相信这是新的网络API的主要点之一。
我试图实现同样的事情。 / p>
ephemeralSessionConfiguration不会存储您的Cookie,因为它的cookieAcceptPolicy总是设置为NEVER,即使您尝试将其更改为其他。对于手动分配的NSURLSessionConfiguration也是如此。
从我的观点来看,这与暂时会话使用内存中的cookie存储的文档形成对比。 p>
我已经针对这个问题发布了一个单独的问题:
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在同一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!