如下一个 普通的 Cookie 的设置,其实来说是太正常不过了
NSHTTPCookie *cookie = [[NSHTTPCookie alloc] initWithProperties:@{
NSHTTPCookieName: @"staging",
NSHTTPCookieValue: @"true",
NSHTTPCookieDomain: url.host,
NSHTTPCookiePath: url.path,
}];
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[storage setCookie:cookie];
但我们有两个测试机 确实无效的, 发现设置完成后 cookies 中居然没有上述刚刚设置的
po [NSHTTPCookieStorage sharedHTTPCookieStorage].cookies
当然如果监听其 Cookies 变化则可以通过 NSHTTPCookieManagerCookiesChangedNotification
来监听。
后来发现
NSHTTPCookie *releaseCookie = [[NSHTTPCookie alloc] initWithProperties:@{
NSHTTPCookieName: @"staging",
NSHTTPCookieValue: @"true",
NSHTTPCookieDomain: url.host,
NSHTTPCookiePath: @"/",
}];
改了一下 Cookie 这个 NSHTTPCookiePath 值 "/ "就可以了 , 因为之前我们的此值为 “” 空。
网友评论