最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

IOS 網(wǎng)絡(luò)請求中設(shè)置cookie

 更新時間:2017年06月20日 15:46:08   投稿:lqh  
這篇文章主要介紹了IOS 網(wǎng)絡(luò)請求中設(shè)置cookie的相關(guān)資料,需要的朋友可以參考下

IOS 網(wǎng)絡(luò)請求中設(shè)置cookie

1. ASIHTTPRequest

ASIHTTPRequest 是一款極其強勁的 HTTP 訪問開源項目。讓簡單的 API 完成復(fù)雜的功能,如:異步請求,隊列請求,GZIP 壓縮,緩存,斷點續(xù)傳,進(jìn)度跟蹤,上傳文件,HTTP 認(rèn)證。

cookie的支持

    如果 Cookie 存在的話,會把這些信息放在 NSHTTPCookieStorage 容器共享,并供下次使用。你可以用 [ ASIHTTPRequest setSessionCookies:nil ] ; 清空所有 Cookies。當(dāng)然,你也可以取消默認(rèn)的Cookie策略,而使自定義的Cookie:

-(NSMutableArray*)retrunCookies{ 
  NSDictionary *properties = [[[NSMutableDictionary alloc] init] autorelease]; 
  [properties setValue:[LoginViewController getLanguageType:loginInfo.lang] forKey:NSHTTPCookieValue]; 
  [properties setValue:@"BENGGURU.GAIA.CULTURE_CODE" forKey:NSHTTPCookieName]; 
  [properties setValue:@"" forKey:NSHTTPCookieDomain]; 
  [properties setValue:[NSDate dateWithTimeIntervalSinceNow:60*60] forKey:NSHTTPCookieExpires]; 
  [properties setValue:@"" forKey:NSHTTPCookiePath]; 
  NSHTTPCookie *cookie = [[[NSHTTPCookie alloc] initWithProperties:properties] autorelease]; 
  return [NSMutableArray arrayWithObject:cookie]; 
}
[request setRequestCookies:[self retrunCookies]];         //發(fā)送cookies,根據(jù)用戶的選擇,返回相應(yīng)語言。

2.  NSMutableURLRequest(可以用于webview)

NSDictionary *properties = [[[NSMutableDictionary alloc] init] autorelease]; 
      [properties setValue:userId forKey:NSHTTPCookieValue]; 
      [properties setValue:@"BENQGURU.GAIA.USERID" forKey:NSHTTPCookieName]; 
      [properties setValue:@"" forKey:NSHTTPCookieDomain]; 
      [properties setValue:[NSDate dateWithTimeIntervalSinceNow:60*60] forKey:NSHTTPCookieExpires]; 
      [properties setValue:@"/" forKey:NSHTTPCookiePath]; 
      NSHTTPCookie *cookie = [[[NSHTTPCookie alloc] initWithProperties:properties] autorelease]; 
      NSDictionary *properties1 = [[[NSMutableDictionary alloc] init] autorelease]; 
      [properties1 setValue:[LoginViewController getLanguageType:loginInfo.lang] forKey:NSHTTPCookieValue]; 
      [properties1 setValue:@"BENGGURU.GAIA.CULTURE_CODE" forKey:NSHTTPCookieName]; 
      [properties1 setValue:@"" forKey:NSHTTPCookieDomain]; 
      [properties1 setValue:[NSDate dateWithTimeIntervalSinceNow:60*60] forKey:NSHTTPCookieExpires]; 
      [properties1 setValue:@"/" forKey:NSHTTPCookiePath]; 
      NSHTTPCookie *cookie1 = [[[NSHTTPCookie alloc] initWithProperties:properties1] autorelease]; 
      NSArray *cookies=[NSArray arrayWithObjects:cookie,cookie1,nil]; 
      NSDictionary *headers=[NSHTTPCookie requestHeaderFieldsWithCookies:cookies]; 
      NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:[object valueForKey:@"url"]]]; 
      [request setValue:[headers objectForKey:@"Cookie"] forHTTPHeaderField:@"Cookie"]; 
      [webView loadRequest:request]; 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論

高邮市| 磐安县| 滁州市| 山阳县| 泽普县| 南江县| 越西县| 绥江县| 察雅县| 南木林县| 天门市| 怀远县| 琼结县| 丽江市| 仁化县| 伊春市| 繁峙县| 安多县| 墨玉县| 大邑县| 临猗县| 绥化市| 同仁县| 焦作市| 贺兰县| 出国| 敦煌市| 五原县| 九寨沟县| 饶河县| 南溪县| 渭南市| 遵义市| 福海县| 泊头市| 娱乐| 屏东市| 平阳县| 卢氏县| 通江县| 莒南县|