iOS保存cookie的方法

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"];

  

上一篇:Ubuntu 16.04中安装谷歌Chrome浏览器


下一篇:mybatis3.2.8 与 hibernate4.3.6 混用