How to manage session ID when using afnetworking

Source: Internet
Author: User
Tags session id

Ask:

As the title implies, I am using afnetworking in an IOS project in which the application talks to a server. When the user signs in, the server responds is sending back a success flag and the response headers contain the session ID .

I am wondering if afnetworking automatically sends the session ID with every subsequent request or should I take care of T His myself in some?

For your information, I has no control over the back-end in terms of how requests is authenticated. I am only building a client this talks to the server.



For:

Yes, your session ID should is sent automatically once you is logged in, as long as the cookies does not expire before the Next request is sent (important detail to being sure of). NSURLConnection , which Afnetworking uses, takes care of the details for this For you.

On the backend afnetworking are using NSURLConnection which in turn automatically updates to NSHTTPCookieStorage store the session. You can manipulate or delete the cookies as you see fit by messing with the cookie storage.

Wanted to appear to the service as not logged in, you could just delete the session cookie associated Domain. Some Services I had worked with would error if you were already logged in and attempt to login again. Additionally there was no-to-check login status. Quick fix, get the cookie from URL and delete them:

Nsarray *cookies = [[Nshttpcookiestorage sharedhttpcookiestorage] Cookiesforurl:networkserveraddress];for ( Nshttpcookie *cookie in cookies) {    [[nshttpcookiestorage sharedhttpcookiestorage] deletecookie:cookie];}


How to manage session ID when using afnetworking

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.