/***** Cookie (Cookies) *****///cookie introduction cookies are generated by the server side and sent to the client client to save the cookie key/value to a text file in a directory if the client supports cookies, The next time you request the same website, you can send a cookie directly to the server cookie name and value the most typical application for developing your own cookies is to determine if a registered user is logged in, log user login information, and simplify the next logon process another important application is "shopping cart" In iOS programs, cookies are supported by default, and programmers do not need to do any processing if the server returns a cookie, it is automatically saved in the sandbox's library/cookies directory/* Cookie's storage Policy */@property Nshttpcookieacceptpolicy Cookieacceptpolicy; Nshttpcookieacceptpolicyalways, never nshttpcookieacceptpolicynever, never NSHTTPCOOKIEAC Ceptpolicyonlyfrommaindocumentdomain only records the primary domain's cookie//hint: If cookies are disabled some network access will not be normal! This option as long as you know, not recommended changes! /* The cookie is saved */saved in a sandbox/library/cookies directory, saved in binary form but still able to see the plaintext of the password, stating that it is unsafe! /* Method of obtaining a cookie *///check if the cookie holds the user's information//1. Take out all the cookiensarray *cookies = [[Nshttpcookiestorage sharedhttpcookiestorage] cookies]; 2. Traverse cookies to check if there is a user name and password for (Nshttpcookie *cookie in cookies) {/** nshttpcookie content stored in name: variable name-> The variable name & value is the value returned from the server: variable values */NSLog (@ "%@", cookie); if ([CookIe.name isequaltostring:@ "UserName"]) {//user name self.nameText.text = cookie.value; } else if ([Cookie.name isequaltostring:@ "UserPassword"]) {//password self.pwdText.text = cookie.value; }}//3. Delete cookie//Read all cookiensarray *cookies = [[nshttpcookiestorage sharedhttpcookiestorage] cookies];//Delete cookiefor ( Nshttpcookie *cookie in cookies) {[[Nshttpcookiestorage sharedhttpcookiestorage] deletecookie:cookie];} /* The defect */cookie of the cookie will be appended to each HTTP request and will increase the additional traffic the cookie in the HTTP request is passed in plaintext, so there is a security risk, unless the size of the Httpscookie is limited to around 4KB, Not suitable for storing complex data information
Cookies in iOS