cookie 内容的获取
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 内容的获取的更多相关文章
- C++ 与 php 的交互 之----- C++ 获取 网页文字内容,获取 php 的 echo 值。
转载请声明出处! http://www.cnblogs.com/linguanh/category/633252.html 距离上次 谈 C++ 制作json 或者其他数据传送给 服务器,时隔两个多月 ...
- 内容页获取当前栏目的上一级栏目ID
发现V9在列表页可以用$parentid 得到当前栏目的父级ID,但在内容页这个函数的值却为空了,需要按下面的写法才行, V9 在内容页获取当前栏目的上一级栏目ID {$CAT[parentid]} ...
- cookie——创建、获取、删除
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- C#中在内容页获取其模板页中的变量,或者值
在CSDN的博文中看到了 muziduoxi 的文章:http://blog.csdn.net/muziduoxi/article/details/5386543 虽然里面提到的方法没有解决我的难题, ...
- Servlet实现禁用cookie重写URL获取session
前言 一个女人让他的程序员丈夫去商店买东西:你去附近的商店买些鸡蛋,如果有香蕉的话,买8个回来,这个丈夫买了8个鸡蛋回来,他的妻子大吃一惊:你为什么买了8个鸡蛋?! 程序员丈夫回答:因为他们有香蕉. ...
- 关于MFC文本框输入内容的获取 与 设置文本框的内容
八月要开始做界面了<( ̄︶ ̄)/,然而目前只会用MFC╮(╯▽╰)╭ 好吧,言归正传,设置好文本框后,要获取用户输入的内容,可以用: GetDlgItemText() ; 这个函数有两个参数,第 ...
- javascript获取iframe框架中页面document对象,获取子页面里面的内容,iframe获取父页面的元素,
javascript获取iframe框架中,加载的页面document对象 因为浏览器安全限制,对跨域访问的页面,其document对象无法读取.设置属性 function getDocument(i ...
- [转]javascript js cookie的存储,获取和删除
本文转自:http://www.jb51.net/article/13240.htm 使用方法: //1.存储Cookie //2.参数说明: 1.参数1:Cookie存储Name,参数2:Cooki ...
- Android初级教程之内容提供者获取联系人信息
内容提供折详细理论知识请参考之前的博文:http://blog.csdn.net/qq_32059827/article/details/51646513 这里新建了三个联系人信息,通过查看系统联系人 ...
随机推荐
- X-UniTMX:导入大型Tiled地图文件(*.tmx)到Unity3d中比较好的插件
因工作原因,需要导入格子数为1200x1200的Tiled地图文件(*.tmx)到Unity3d中显示出来.尝试过一些其它插件,后面发现X-UniTMX是比较好用的. X-UniTMXhttp://f ...
- [mondrian] 分析一个简单的schema文件
<?xml version="1.0" encoding="UTF-8"?> <Schema name="Mondrian" ...
- jQuery 2.0.3 源码分析 bind/live/delegate/on
传统的时间处理: 给某一个元素绑定一个点击事件,传入一个回调句柄处理 element.addEventListener('click',doSomething,false); 这样的绑定如果页面上面有 ...
- Oracle 表死锁 解决
问题:更新的Update语句一直在更新 卡在执行update语句的地方. 清除的方法: Oracle表死锁解除 我是在plsql中处理 1.先查询 select * from v$locked ...
- java操作字符串,重点是记录一次使用replaceAll对字符串的操作
符串常用操作(String类) 字符串查找 String提供了两种查找字符串的方法,即indexOf与lastIndexOf方法. 1.indexOf(String s) 该方法用于返回参数字符串s在 ...
- Eclipse添加jsp页面后引入java指令报错解决方法
新建jsp页面老提示: Multiple annotations found at this line: - The superclass "javax.servlet.http.HttpS ...
- java代码抓取网页邮箱
实现思路:1.使用java.net.URL对象,绑定网络上某一个网页的地址2.通过java.net.URL对象的openConnection()方法获得一个HttpConnection对象3.通过Ht ...
- ios基础篇(六)——UITextView的常用方法及技巧
上篇说到了UITextField,我们先来说说UITextView和UITextField的不同: UITextView支持多行输入; UITextFiled只支持单行; UITextView没有pl ...
- BZOJ2280 [Poi2011]Plot
恩..这题真是sxbk 我们先二分答案,然后判断答案是否满足要求 判断方法是二分当前段的长度一直做到底,当然我们可以用倍增这样快一点,直接随机增量就可以了 然后就是卡常..... 然后就是卡精度QAQ ...
- Spring的web应用启动加载数据字典方法
在一个基于Spring的web项目中,当我们需要在应用启动时加载数据字典时,可写一个监听实现javax.servlet.ServletContextListener 实现其中的contextIniti ...