版权声明:本文为博主原创文章,未经博主允许不得转载。

 

目录(?)[+]

 

1. ASIHTTPRequest

ASIHTTPRequest 是一款极其强劲的 HTTP 访问开源项目。让简单的 API 完成复杂的功能,如:异步请求,队列请求,GZIP 压缩,缓存,断点续传,进度跟踪,上传文件,HTTP 认证。

cookie的支持

如果 Cookie 存在的话,会把这些信息放在 NSHTTPCookieStorage 容器中共享,并供下次使用。你可以用 [ ASIHTTPRequest setSessionCookies:nil ] ; 清空所有 Cookies。当然,你也可以取消默认的Cookie策略,而使自定义的Cookie:

  1. -(NSMutableArray*)retrunCookies{
  2. NSDictionary *properties = [[[NSMutableDictionary alloc] init] autorelease];
  3. [properties setValue:[LoginViewController getLanguageType:loginInfo.lang] forKey:NSHTTPCookieValue];
  4. [properties setValue:@"BENGGURU.GAIA.CULTURE_CODE" forKey:NSHTTPCookieName];
  5. [properties setValue:@"" forKey:NSHTTPCookieDomain];
  6. [properties setValue:[NSDate dateWithTimeIntervalSinceNow:60*60] forKey:NSHTTPCookieExpires];
  7. [properties setValue:@"" forKey:NSHTTPCookiePath];
  8. NSHTTPCookie *cookie = [[[NSHTTPCookie alloc] initWithProperties:properties] autorelease];
  9. return [NSMutableArray arrayWithObject:cookie];
  1. }
  1. [request setRequestCookies:[self retrunCookies]];                  //发送cookies,根据用户的选择,返回相应语言。

2.  NSMutableURLRequest(可以用于webview)

  1. NSDictionary *properties = [[[NSMutableDictionary alloc] init] autorelease];
  2. [properties setValue:userId forKey:NSHTTPCookieValue];
  3. [properties setValue:@"BENQGURU.GAIA.USERID" forKey:NSHTTPCookieName];
  4. [properties setValue:@"" forKey:NSHTTPCookieDomain];
  5. [properties setValue:[NSDate dateWithTimeIntervalSinceNow:60*60] forKey:NSHTTPCookieExpires];
  6. [properties setValue:@"/" forKey:NSHTTPCookiePath];
  7. NSHTTPCookie *cookie = [[[NSHTTPCookie alloc] initWithProperties:properties] autorelease];
  8. NSDictionary *properties1 = [[[NSMutableDictionary alloc] init] autorelease];
  9. [properties1 setValue:[LoginViewController getLanguageType:loginInfo.lang] forKey:NSHTTPCookieValue];
  10. [properties1 setValue:@"BENGGURU.GAIA.CULTURE_CODE" forKey:NSHTTPCookieName];
  11. [properties1 setValue:@"" forKey:NSHTTPCookieDomain];
  12. [properties1 setValue:[NSDate dateWithTimeIntervalSinceNow:60*60] forKey:NSHTTPCookieExpires];
  13. [properties1 setValue:@"/" forKey:NSHTTPCookiePath];
  14. NSHTTPCookie *cookie1 = [[[NSHTTPCookie alloc] initWithProperties:properties1] autorelease];
  15. NSArray *cookies=[NSArray arrayWithObjects:cookie,cookie1,nil];
  16. NSDictionary *headers=[NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
  17. NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:[object valueForKey:@"url"]]];
  18. [request setValue:[headers objectForKey:@"Cookie"] forHTTPHeaderField:@"Cookie"];
  19. [webView loadRequest:request];

IOS 网络请求中设置cookie的更多相关文章

  1. 网络请求中的cookie与set-Cookie的交互模式的一些问题解析

    首先我们需要思考,很多问题. 1.当很多人访问统一个网服务器,服务器如何来区分不同的用户呢? 答:sessionid,sessionid保证了浏览器和服务器唯一性的通信凭证号码,session保存在服 ...

  2. iOS 网络请求中的challenge

    这里有一篇文章,请阅读,感谢作者!http://blog.csdn.net/kmyhy/article/details/7733619 当请求的网站有安全认证问题时,都需要通过 [[challenge ...

  3. iOS 网络请求中的空类型字符串转换

    创建一个工具类,   .h: #import <Foundation/Foundation.h> @interface MySetNullWithStrTool : NSObject +( ...

  4. IOS 在http请求中使用cookie

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainbird.blog.51cto.com/211214/805173 一直以 ...

  5. iOS网络请求-AFNetworking源码解析

    趁着端午节日,自己没有什么过多的安排,准备花4-5天左右,针对网络请求源码AFNetworking和YTKNetwork进行解析以及这两年多iOS实际开发经验(其实YTKNetwork也是对AFNet ...

  6. Angularjs之如何在跨域请求中传输Cookie

    一般情况我们在使用WebApi之类的技术时,都会遇到跨域的问题,这个只需要在服务端做一下处理即可. 如果这些GET或POST请求不需要传递Cookie数据的话,就没什么问题了,但如果需要,那么会发现 ...

  7. 【转载】一步一步搭建自己的iOS网络请求库

    一步一步搭建自己的iOS网络请求库(一) 大家好,我是LastDay,很久没有写博客了,这周会分享一个的HTTP请求库的编写经验. 简单的介绍 介绍一下,NSURLSession是iOS7中新的网络接 ...

  8. iOS网络请求之multipart/form-data提交数据

    multipart/form-data表单数据 在http网络请求中,post没有请求长度的限制,因为post把数据放在了body中,而不是像Get一样放在了浏览器的地址栏中(可以这么理解), 所以相 ...

  9. springmvc接口ios网络请求

    springmvc:   application/json;charset=utf-8的ios网络请求: 后台使用 @RequestBody注解参数接收:

随机推荐

  1. [Machine Learning]k-NN

    k-NN最近邻算法 基本思想: 对未知样本X,从训练样本集中获取与其最相近的k个样本,利用这k个样本的类别预测未知样本X的类别. 如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大 ...

  2. 查看python的路径

    >>> import sys >>> sys.path

  3. linux namespace note

    --------------------------------- from http://oldwiki.linux-vserver.org/Namespaces //开源不只是代码,还有思想 Na ...

  4. Leetcode: Guess Number Higher or Lower II

    e are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess ...

  5. 企业Openvpn环境部署

                   企业Openvpn环境部署                                         作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任 ...

  6. 使用Mysql修改密码命令更改root的密码

    使用Mysql修改密码命令更改root的密码. 进入Mysql数据库命令行方式有两种方式: 方式一:在Mysql开始菜单里包含Mysql命令行客户端,只要点击输入root的密码即可进入. 方式二:在D ...

  7. ACM常用算法及练习(1)

    ACM常用算法及练习 第一阶段:练经典常用算法,下面的每个算法给我打上十到二十遍,同时自己精简代码,因为太常用,所以要练到写时不用想,10-15分钟内打完,甚至关掉显示器都可以把程序打出来. 1.最短 ...

  8. POJ 1811 Prime Test(Miller-Rabin & Pollard-rho素数测试)

    Description Given a big integer number, you are required to find out whether it's a prime number. In ...

  9. paper 79:MATLAB函数,interp1

    在matlab中有一个interp1()函数,可以帮助解决问题,具体情况如下:MATLAB中的插值函数为interp1,其调用格式为: yi= interp1(x,y,xi,'method') 其中x ...

  10. 关于MVC4中EFCoderFirst 数据迁移的三句经典指令

    首先输入这句指令     enable-migrations -contexttypename SchoolContext  ---------(SchoolContext为你设置的数据库名)它会自动 ...