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