码迷,mamicode.com
首页 > 移动开发 > 详细

iOS保存cookie的方法

时间:2016-03-12 17:21:02      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

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

  

iOS保存cookie的方法

标签:

原文地址:http://www.cnblogs.com/letMalikelyo/p/5269202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!