Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Directory (?) [+]
1. ASIHTTPRequest
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:
[Plain]View PlainCopy
- -(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];
[Plain]View PlainCopy
- }
[Plain]View PlainCopy
- [Request Setrequestcookies:[self retruncookies]; Send cookies, depending on the user's choice, to return to the appropriate language.
2.
nsmutableurlrequest (can be used for WebView)
[Plain]View PlainCopy
- 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];
Setting cookies in IOS network requests