SURLRequest*request =[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]]; NSURLConnection*connection =[NSURLConnection connectionWithRequest:request delegate:self]; -(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response { NSHTTPURLResponse*HTTPResponse=(NSHTTPURLResponse*)response; NSDictionary*fields =[HTTPResponse allHeaderFields]; NSString*cookie =[fields valueForKey:"Set-Cookie"];// It is your cookie } //保存好Cookie,当另一个request要用到这个cookies时,用如下方法加入: NSMutableURLRequest*request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]]; [request addValue:cookie forHTTPHeaderField:"Cookie"];
时间: 2024-10-25 16:54:19