我有手动将域的 cookie 应用到 AFHTTPSessionManager 的请求序列化程序的代码。当我执行代码时,我看到 cookie 是随请求一起发送的。但是,我似乎无法让经理自动处理它们。
有没有办法让 AFHTTPSessionManager 自动将 cookie 应用于域内特定路径的请求?
-(void)configureCookiesForManager:(AFHTTPSessionManager*)_manager
{
NSArray *cookiesArray = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:_manager.baseURL];
NSDictionary *cookieHeaders = [NSHTTPCookie requestHeaderFieldsWithCookies:cookiesArray];
for(NSString* key in cookieHeaders)
{
NSString* value = cookieHeaders[key];
[_manager.requestSerializer setValue:cookieHeaders[key] forHTTPHeaderField:key];
}
我努力了:
cookieStorage.cookieAcceptPolicy = NSHTTPCookieAcceptPolicyAlways;
[NSURLSessionConfiguration defaultSessionConfiguration].HTTPCookieAcceptPolicy = NSHTTPCookieAcceptPolicyAlways; //could be duplicate
[NSURLSessionConfiguration defaultSessionConfiguration].HTTPShouldSetCookies = YES;
__manager.requestSerializer.HTTPShouldHandleCookies = YES;
这是我的 cookie 的样子:
[NSHTTPCookie]
name = name
value = MyPersistentCookie
domain = 10.1.1.111
path = /
expiresDate = 2017-02-19 19:08:57 +0000
sessionOnly = 0
secure = 0
comment = (null)
commentURL = (null)
version