<强> IOS网络请求中设置饼干强>
<强> 1。ASIHTTPRequest 强>
ASIHTTPRequest是一款极其强劲的HTTP访问开源项目。让简单的API完成复杂的功能,如:异步请求,队列请求,GZIP压缩,缓存,断点续传,进度跟踪,上传文件,HTTP认证。
<强>饼干的支持强>
,,,如果饼存在的话,会把这些信息放在NSHTTPCookieStorage容器中共享,并供下次使用。你可以用[ASIHTTPRequest setSessionCookies: nil);清空所有饼干。当然,你也可以取消默认的饼干策略,而使自定义的饼干:
——(NSMutableArray *) retrunCookies { NSDictionary *属性=[[[称为unaryoperations alloc] init] autorelease); [属性setValue: [LoginViewController getLanguageType: loginInfo。朗]forKey: NSHTTPCookieValue]; 【属性setValue: @ " BENGGURU.GAIA。CULTURE_CODE”forKey NSHTTPCookieName):; 【属性setValue: @”“forKey: NSHTTPCookieDomain); 【属性setValue: [NSDate dateWithTimeIntervalSinceNow: 60 * 60] forKey: NSHTTPCookieExpires); 【属性setValue: @”“forKey: NSHTTPCookiePath); NSHTTPCookie *饼干=[[[NSHTTPCookie alloc] initWithProperties属性):生成); 返回(NSMutableArray arrayWithObject cookie):; }
(请求setRequestCookies:[自我retrunCookies]];//发送饼干,根据用户的选择,返回相应语言。
<强> 2只;NSMutableURLRequest(可以用于webview) 强>
NSDictionary *属性=[[[称为unaryoperations alloc] init] autorelease); 【属性setValue: userId forKey NSHTTPCookieValue):; 【属性setValue: @ " BENQGURU.GAIA。USERID”forKey NSHTTPCookieName):; 【属性setValue: @”“forKey: NSHTTPCookieDomain); 【属性setValue: [NSDate dateWithTimeIntervalSinceNow: 60 * 60] forKey: NSHTTPCookieExpires); 【属性setValue: @”/癴orKey: NSHTTPCookiePath); NSHTTPCookie *饼干=[[[NSHTTPCookie alloc] initWithProperties属性):生成); NSDictionary * properties1=[[[称为unaryoperations alloc] init] autorelease); [properties1 setValue: [LoginViewController getLanguageType: loginInfo。朗]forKey: NSHTTPCookieValue]; BENGGURU.GAIA [properties1 setValue: @”。CULTURE_CODE”forKey NSHTTPCookieName):; [properties1 setValue: @”“forKey: NSHTTPCookieDomain); [properties1 setValue: [NSDate dateWithTimeIntervalSinceNow: 60 * 60] forKey: NSHTTPCookieExpires); [properties1 setValue: @”/癴orKey: NSHTTPCookiePath); NSHTTPCookie * cookie1=[[[NSHTTPCookie alloc] initWithProperties properties1):生成); NSArray *饼干=(NSArray arrayWithObjects:饼干、cookie1 nil); NSDictionary *头=[NSHTTPCookie requestHeaderFieldsWithCookies饼干):; NSMutableURLRequest *请求=[NSMutableURLRequest requestWithURL:(NSURL URLWithString:[对象valueForKey: @ " url "]]]; (请求setValue(标题:objectForKey: @“饼干”)forHTTPHeaderField: @“饼干”); (webView loadRequest:请求); >之前感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
IOS网络请求中设置饼干