NSMutableArray *cookiesStoreAll = [[NSMutableArray alloc]init];
 NSUInteger totalNumberOfCookies;    
 NSMutableURLRequest *request_get = [[[NSMutableURLRequest alloc] init] autorelease]; 
 [request_get setURL:[NSURL URLWithString:urlStr]]; 
 [request_get setHTTPMethod:@"GET"];
 [request_get setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
 [request_get setHTTPShouldHandleCookies:YES]; 
 // doGet - response 
 
 NSHTTPURLResponse *response_get = nil;  
 NSError *error_get = nil; 
 NSData *responseData_get = [NSURLConnection sendSynchronousRequest:request_get returningResponse:&response_get error:&error_get]; 
 NSString *data_get=[[NSString alloc]initWithData:responseData_get encoding:NSUTF8StringEncoding];   
 //get the cookies by using the header cookies  
  [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; 
 NSDictionary *headerFields_get = [(NSHTTPURLResponse*)response_get allHeaderFields]; 
 NSURL *urlCookies_get = [NSURL URLWithString:urlStr]; 
 NSArray *cookies_get = [NSHTTPCookie cookiesWithResponseHeaderFields:headerFields_get forURL:urlCookies_get];    
// retrieve the cookies from url by sharedHTTPCookieStore 
 NSArray *cookiesUse_get = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:urlCookies_get];
 NSUInteger numberOfCookiesUse_get = [cookiesUse_get count];  
 NSUInteger numberOfCookies_get = [cookies_get count];
 NSLog(@"numberOfCookies_get==:%d", numberOfCookies_get);
 
 for (NSHTTPCookie *cookie in cookies_get) {
  NSLog(@"numberOfCookies_get :Name: %@ : Value: %@", cookie.name, cookie.value);
 }
 
 NSLog(@"numberOfCookiesUse_get==:%d", numberOfCookiesUse_get);
 
 for (NSHTTPCookie *cookie in cookiesUse_get) {
  NSLog(@"numberOfCookiesUse_get :Name: %@ : Value: %@", cookie.name, cookie.value);
 }
 
 // Cookie - add the array to the cookieStoreAll 
 [cookiesStoreAll addObjectsFromArray: cookiesUse_get]; 
 totalNumberOfCookies = [cookiesStoreAll count];   
 //NSString *realCookieValue;   
 // get the needed cookie and convent to the NSString  
 for(int j=0; j<totalNumberOfCookies; j++)  {   
  NSLog(@"numberOfCookiesUse_get==:%@", [[cookiesStoreAll objectAtIndex:j] name]);
  NSLog(@"numberOfCookiesUse_get==:%@",[[cookiesStoreAll objectAtIndex:j] value]);
  //NSString *realCookieName = [[cookiesStoreAll objectAtIndex:j] name];     
  //if([realCookieName isEqualToString: @"neededCookieName"])     
  //{         
   //realCookieValue = [[cookiesStoreAll objectAtIndex:j] value];         
   //cookiesString = [NSString stringWithFormat:@"neededCookieName=%@; ", realCookieValue];     
  //}  
 }

cookie 内容的获取的更多相关文章

  1. C++ 与 php 的交互 之----- C++ 获取 网页文字内容,获取 php 的 echo 值。

    转载请声明出处! http://www.cnblogs.com/linguanh/category/633252.html 距离上次 谈 C++ 制作json 或者其他数据传送给 服务器,时隔两个多月 ...

  2. 内容页获取当前栏目的上一级栏目ID

    发现V9在列表页可以用$parentid 得到当前栏目的父级ID,但在内容页这个函数的值却为空了,需要按下面的写法才行, V9 在内容页获取当前栏目的上一级栏目ID {$CAT[parentid]} ...

  3. cookie——创建、获取、删除

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. C#中在内容页获取其模板页中的变量,或者值

    在CSDN的博文中看到了 muziduoxi 的文章:http://blog.csdn.net/muziduoxi/article/details/5386543 虽然里面提到的方法没有解决我的难题, ...

  5. Servlet实现禁用cookie重写URL获取session

    前言 一个女人让他的程序员丈夫去商店买东西:你去附近的商店买些鸡蛋,如果有香蕉的话,买8个回来,这个丈夫买了8个鸡蛋回来,他的妻子大吃一惊:你为什么买了8个鸡蛋?! 程序员丈夫回答:因为他们有香蕉. ...

  6. 关于MFC文本框输入内容的获取 与 设置文本框的内容

    八月要开始做界面了<( ̄︶ ̄)/,然而目前只会用MFC╮(╯▽╰)╭ 好吧,言归正传,设置好文本框后,要获取用户输入的内容,可以用: GetDlgItemText() ; 这个函数有两个参数,第 ...

  7. javascript获取iframe框架中页面document对象,获取子页面里面的内容,iframe获取父页面的元素,

    javascript获取iframe框架中,加载的页面document对象 因为浏览器安全限制,对跨域访问的页面,其document对象无法读取.设置属性 function getDocument(i ...

  8. [转]javascript js cookie的存储,获取和删除

    本文转自:http://www.jb51.net/article/13240.htm 使用方法: //1.存储Cookie //2.参数说明: 1.参数1:Cookie存储Name,参数2:Cooki ...

  9. Android初级教程之内容提供者获取联系人信息

    内容提供折详细理论知识请参考之前的博文:http://blog.csdn.net/qq_32059827/article/details/51646513 这里新建了三个联系人信息,通过查看系统联系人 ...

随机推荐

  1. robotframework笔记11

    测试用例的语法 基本语法 测试用例构造测试用例表中可用 关键词. 关键字可以进口 测试库 或 资源 文件 或创建的 关键字表 的测试用例文件 本身. 测试用例表中第一列包含测试用例的名称. 一个 测试 ...

  2. hibernate的懒加载问题

    产生原因: 当使用hibernate查询一个对象的时候,如果Session关闭,再调用该对象关联的集合或者对象的时候,会产生懒加载异常! 解决方案: 方案一: 在Session关闭之前,查询对象关联的 ...

  3. 函数内部的函数中的this都是指向window

    刚看到一个问题关于this的, var name="the window"; var object={ name:"silence", packname:fun ...

  4. Populating Next Right Pointers in Each Node [LeetCode]

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

  5. Css:背景色透明,内容不透明之终极方法!兼容所有浏览器

    转载 http://www.cnblogs.com/jikey/archive/2012/08/31/2665880.html <!DOCTYPE html PUBLIC "-//W3 ...

  6. 支持SQL Server数据库又支持MongoDB数据库的数据访问设计

    网站整体架构建议采用工厂模式 分别包括:数据访问层DAL,数据访问接口层IDAL,工厂层DALFactory,业务逻辑层,显示层这样的架构方式 在WebConfig配置采用何种数据库的数据访问层 &l ...

  7. finally块中的代码一定会执行吗?

    在Sun Tutorial中有这样一句话:The finally block always executes when the try block exits. This ensures that t ...

  8. protobuf 安装 及 小测试

    参考:http://shift-alt-ctrl.iteye.com/blog/2210885 版本: 2.5.0 百度云盘上有jar包. mac 上安装: 新建:/Users/zj/software ...

  9. Excel VBA记录

    -----------快捷键---------- 函数等提示(默认):ctrl+j 注释:上单引号' 设置单元格为空可以用:empty/null -----------基础语法--------- 基本 ...

  10. [转]iOS/iphone开发如何为苹果开发者帐号APPID续费

    原文地址:http://blog.sina.com.cn/s/blog_68661bd80101nme6.html 其实相当的简单,这篇内容是给财务看的,有的地方连我自己看了都感觉有点...但如果不详 ...