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 这里新建了三个联系人信息,通过查看系统联系人 ...
随机推荐
- python 练习 17
#!/usr/bin/python # -*- coding: UTF-8 -*- f1 = 1 f2 = 1 for i in range(1,21): print '%12d %12d' % (f ...
- selenium+python笔记8
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 定制浏览器 """ imp ...
- Linux下修改系统时间并写入BIOS
我们一般使用“date -s”命令来修改系统时间.比如将系统时间设定成2005年7月26日的命令如下. #date -s 07/26/2005 将系统时间设定成下午11点12分0秒的命令如下. #da ...
- python 使用*args 和**kwargs
def fun_var_args(farg, *args): print "arg:", farg for value in args: print "another a ...
- WMI执行远程文件(RPC)
通过wmi在远程机上执行命令(wmi:windows management interface 可以通过一个公共的接口访问不同操作系统(windows系统)的构成单元,利用它可以高效的管理远程和本地的 ...
- hdu 3853LOOPS (概率DP)
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- iOS App从点击到启动
程序启动之前 从exec()开始 main()函数是整个程序的入口,在程序启动之前,系统会调用exec()函数.在Unix中exec和system的不同在于,system是用shell来调用程序,相当 ...
- 安装VC6提示找不到ACME时的解决办法
将安装程序COPY到电脑上1.打开setupwiz.ini,把"acme=acmboot.exe"改为"=acmsetup.exe";2.STF=setup/v ...
- SecureCRT从本传相片到服务器的注意事项
rz -y -be 注意,要加上参数be
- placeholder修改颜色
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color: #f00; } ::-moz-placeholder { /* Mozilla Fir ...