美文网首页
修改cooke并保存

修改cooke并保存

作者: 我是菜鸟66666 | 来源:发表于2016-08-30 17:34 被阅读0次

    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并保存

          本文链接:https://www.haomeiwen.com/subject/lfxqettx.html