I am writing a REST client (with AFNetworking) and need the ability to trigger the creation of a new session within a single instance of an application.
In other words, I would like to:
1 - Authenticate with server
2 - Do some REST calls
3 - Simulate "Log out"
4 - Re-authenticate with server
5 - Do some more REST calls
AFNetworking is great with making that initial authentication and REST calls, but I can't figure out how I would clear the session and "reset" the connection within the same instance.
When I used ASIHTTP, I just did:
[ASIHTTPRequest clearSession];
Is there a way to do something similar with AFNetworking?
相关问题
- Design RESTful service with multiple ids
- Core Data lightweight migration crashes after App
- Axios OPTIONS instead of POST Request. Express Res
- Plain (non-HTML) error pages in REST api
- How can I implement password recovery in an iPhone
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Sqlite: How do I reset all database tables?
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
Rest calls as far as I know are not session based. Meaning you can't simulate an authentication and log-out session in a particular call. What I think you can do is to Authenticate for every call made to the end point. So for every end point(Method), you authenticate the caller. I think that's the bets you can do in a restful system.
Use
AFHTTPClient
(see the API client in the example project).Credentials can be set with
-setAuthorizationHeaderWithUsername:password:
. Each request created from that HTTP client will have anAuthorization
HTTP header, kind of like a browser session.When the user logs out, or you want to clear credentials, do
-clearAuthorizationHeader
.Even simpler.