posts - 186,  comments - 17,  views - 35万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
 

目录(?)[+]

 

1. ASIHTTPRequest

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

 

cookie的支持

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

 

[plain] view plain copy
  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];  
[plain] view plain copy
  1. }  
[plain] view plain copy
  1. [request setRequestCookies:[self retrunCookies]];                  //发送cookies,根据用户的选择,返回相应语言。  



 

2.  NSMutableURLRequest(可以用于webview)

[plain] view plain copy
  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];  
posted on   ZOYOO  阅读(2754)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示