编程技术记录

世界你好!

可能的一个原因是设置了NSHTTPCookieDiscard这个key

    NSMutableDictionary<NSString *, id> *properties = [NSMutableDictionary dictionary];
    properties[NSHTTPCookieName] = @"aaa";
    properties[NSHTTPCookieValue] = @"bbb";
//    properties[NSHTTPCookieDiscard] = @"FALSE"; 该选项不生效,设置后会影响NSHTTPCookieExpires
    properties[NSHTTPCookiePath] = @"/ccc/ddd"; 
    properties[NSHTTPCookieExpires] = [[NSDate new] dateByAddingTimeInterval:3*3600*24];
    properties[NSHTTPCookieDomain] = @"xxx.yyy.zzz";
    NSHTTPCookie *cookie = [[NSHTTPCookie alloc] initWithProperties:properties];
    NSLog(@"%@",cookie); // cookide 的过期时间应该设置成功了

发表回复

© Beli. All Rights Reserved.