This article reprinted to http://tec.5lulu.com/detail/108k0n1e626py8s96.html
1ASIHTTPRequest
ASIHTTPRequest is an extremely robust HTTP access to open source project. Let the simple API complete complex functions such as: Asynchronous request, queue request, GZIP compression, cache, breakpoint continuation, progress tracking, upload file, HTTP authentication.
Support for Cookies
If the Cookie exists, it will be shared in the Nshttpcookiestorage container for the next use. You can use [ASIHTTPRequest setsessioncookies:nil]; Clear all Cookies. Of course, you can also cancel the default cookie policy and make the custom 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 ] forkey:nshttpcookieexpires];
- [Properties SetValue: @"" forkey:nshttpcookiepath];
- Nshttpcookie *Cookie = [[[Nshttpcookie alloc] Initwithproperties:properties] autorelease];
- return [nsmutablearray arraywithobject:cookie];
- }
- [Request Setrequestcookies: [self retruncookies]]; //Send cookies, depending on the user's choice, to return the appropriate language.
2
nsmutableurlrequest (can be used for 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:] Forkey:nshttpcookieexpires];
- [Properties SetValue: @"/" forkey:nshttpcookiepath];
- nshttpcookie *= [[[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:] Forkey:nshttpcookieexpires];
- [properties1 setValue: @"/" forkey:nshttpcookiepath];
- nshttpcookie *= [[[nshttpcookie Alloc] Initwithproperties: properties1] Autorelease];
- nsarray *cookies=[nsarray arraywithobjects:cookies,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];
Setting cookies in IOS network requests