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

 

目录(?)[+]

 

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. Android --MainActivity模板

    系统自带的NavigationDrawerFragment 1.自动生成NavigationDrawerFragment,onCreatView代码如下 @Override public View o ...

  2. 解决: Fail to create empty document

    做 Programming Windows with MFC 2nd 的例子 MyWord 的时候. 发现启动的时候总是报错: Fail to create empty document. 搜索了一下 ...

  3. Linux bash运维操作日志审计(单服务器)

    目前公司有几台机器比较重要,需要把所有用户的操作记录下来,于是就是参照资料来完成 1. vim /etc/profile.d/oplogrc.sh logdir=/opt/oplog userdir= ...

  4. nodejs 入门

    1. hello word hello.js console.log("hello"); node hello.js即可 2.调试 如果 npm install太慢 可以使用国内淘 ...

  5. C# MVC 实现登录的5种方式

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷.  学无止境,精益求精    小弟之前做过三月的MVC,后来又一直webFo ...

  6. <s:select>中list获取action中数据

    jsp: <s:select name="cate1.id" list="cate1list" listKey="id" listVa ...

  7. Java FX中TreeView节点选中和双击事件监听

    TreeItem<String> treeRoot = new TreeItem<String>("Root"); treeRoot.setExpanded ...

  8. AngularJs Test demo &front end MVVM implementation conjecture and argue.

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...

  9. Uva 11538 - Chess Queen

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  10. Android studio删除工程项目,androidstudio

    本新手最近学Android都是用的eclipse.其实个人觉得eclipse不错,可能接触Android不久,倒也不觉得它慢还是怎样.对于Google的Android studio也是早有耳闻,前两天 ...