iphone 使用 获取cookie

int i;

NSDictionary *dic = [NSDictionary dictionaryWithObject:@"name=value; path=/; domain=.test.com;, name2=value2; path=/;" forKey:@"Set-Cookie"];

NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:dic forURL:[NSURL URLWithString:@"http://www.foo.com/"]];

 

for (i = 0; i < [cookies count]; i++)

{

NSHTTPCookie *cookie = [cookies objectAtIndex:i];

NSLog(@"%@ for %@",[cookie name], [cookie domain]);

}

for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies])

{

    NSLog(@"name: '%@'\n",   [cookie name]);

    NSLog(@"value: '%@'\n",  [cookie value]);

    NSLog(@"domain: '%@'\n", [cookie domain]);

posted on 2010-10-22 20:31  xYx  阅读(774)  评论(0编辑  收藏  举报

导航