我可以在创建 session 后更新 NSURLSession 配置中的 cookie 吗?
我使用此代码更新 cookie,但它似乎不起作用。
self.session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
self.session.configuration.HTTPShouldSetCookies = NO;
self.session.configuration.HTTPCookieAcceptPolicy = NSHTTPCookieAcceptPolicyAlways;
self.session.configuration.HTTPAdditionalHeaders = [NSHTTPCookie requestHeaderFieldsWithCookies:cookiesArray];
谢谢,
不,您不能,您必须在创建 session 之前创建配置,来自 Apple 文档:
It is important to configure your NSURLSessionConfiguration object appropriately before using it to initialize a session object. Session objects make a copy of the configuration settings you provide and use those settings to configure the session. Once configured, the session object ignores any changes you make to the NSURLSessionConfiguration object. If you need to modify your transfer policies, you must update the session configuration object and use it to create a new NSURLSession object.
例如
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.HTTPShouldSetCookies = NO;
configuration.HTTPCookieAcceptPolicy = NSHTTPCookieAcceptPolicyAlways;
configuration.HTTPAdditionalHeaders = [NSHTTPCookie requestHeaderFieldsWithCookies:cookiesArray];
NSURLSession *session = [NSURLSession initWithSessionConfiguration:configuration];
关于ios - 我可以在创建 NSURLSession 后更新其配置中的 cookie 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26422360/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |