国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

IOS 網絡請求中設置cookie

2020-07-26 02:47:19
字體:
來源:轉載
供稿:網友

IOS 網絡請求中設置cookie

1. ASIHTTPRequest

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

cookie的支持

    如果 Cookie 存在的話,會把這些信息放在 NSHTTPCookieStorage 容器中共享,并供下次使用。你可以用 [ ASIHTTPRequest setSessionCookies:nil ] ; 清空所有 Cookies。當然,你也可以取消默認的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]];         //發送cookies,根據用戶的選擇,返回相應語言。

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]; 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成武县| 汕头市| 九龙城区| 城固县| 中牟县| 安达市| 朔州市| 新龙县| 新津县| 桐城市| 井陉县| 米林县| 浏阳市| 吉林市| 上饶市| 盘锦市| 连南| 清镇市| 宜阳县| 乐亭县| 南部县| 油尖旺区| 酒泉市| 花莲市| 电白县| 伊金霍洛旗| 黄梅县| 离岛区| 金坛市| 昭苏县| 丰县| 南木林县| 田阳县| 宽城| 普陀区| 古交市| 随州市| 麻江县| 五寨县| 孝义市| 金秀|