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

首頁 > 系統(tǒng) > iOS > 正文

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

2019-10-21 18:45:55
字體:
供稿:網(wǎng)友

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

1. ASIHTTPRequest

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

cookie的支持

    如果 Cookie 存在的話,會(huì)把這些信息放在 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]; 

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


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到IOS開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 从江县| 广饶县| 叙永县| 莒南县| 五河县| 嵊泗县| 大厂| 伽师县| 五指山市| 庐江县| 饶阳县| 西华县| 盐池县| 额济纳旗| 山东| 临西县| 曲周县| 张家川| 海兴县| 沾化县| 文水县| 敦煌市| 正蓝旗| 化德县| 宁乡县| 玛纳斯县| 新和县| 宁波市| 鹤峰县| 伊宁市| 库尔勒市| 鄂托克前旗| 天全县| 乐至县| 阿鲁科尔沁旗| 新巴尔虎左旗| 陇西县| 白城市| 徐闻县| 斗六市| 鄂伦春自治旗|