Cookies in iOS

Source: Internet
Author: User

/***** 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-&gt    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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.