修改cooke并保存

NSHTTPCookieStorage*cookieJar = [NSHTTPCookieStoragesharedHTTPCookieStorage];

NSArray*cookies = [NSArrayarrayWithArray:[cookieJarcookies]];

for(NSHTTPCookie*cookieincookies)

{

//从cookies中获取sessionid并保存.

NSDictionary*cookieProperties = [[NSMutableDictionaryalloc]init];

[cookiePropertiessetValue:[responseObjectvalueForKey:@"token"]forKey:NSHTTPCookieValue];

[cookiePropertiessetValue:@"token"forKey:NSHTTPCookieName];

[cookiePropertiessetValue:@"m.thirtydevs.com"forKey:NSHTTPCookieDomain];

//没有增加新cookie也许是由于没有把NSHTTPCookieExpires和NSHTTPCookiePath设置好.

//NSLog(@"%@",[responseObject valueForKey:@"token"]);

//[cookieProperties setValue:[responseObject valueForKey:@"token"] forKey:NSHTTPCookieExpires];

[cookiePropertiessetValue:[cookiepath]forKey:NSHTTPCookiePath];

NSHTTPCookie*ncookie = [[NSHTTPCookiealloc]initWithProperties:cookieProperties];

[[NSHTTPCookieStoragesharedHTTPCookieStorage]setCookie:ncookie];

}

NSLog(@"2:%@",[[NSHTTPCookieStoragesharedHTTPCookieStorage]cookies]);

//NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];

NSArray*cookies1 = [NSArrayarrayWithArray:[[NSHTTPCookieStoragesharedHTTPCookieStorage]cookies]];

////NSLog(@"%@",cookies);

NSData*data = [NSKeyedArchiverarchivedDataWithRootObject:cookies1];

[[NSUserDefaultsstandardUserDefaults]setObject:dataforKey:@"sessionCookies"];

你可能感兴趣的:(修改cooke并保存)