Resetting basic authentication credentials with AFNetworking

后端 未结 3 1198
花落未央
花落未央 2021-02-08 23:59

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,

相关标签:
3条回答
  • 2021-02-09 00:24

    Even simpler.

    [request setHTTPShouldHandleCookies:NO];
    
    0 讨论(0)
  • 2021-02-09 00:35

    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.

    0 讨论(0)
  • 2021-02-09 00:46

    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 an Authorization HTTP header, kind of like a browser session.

    When the user logs out, or you want to clear credentials, do -clearAuthorizationHeader.

    0 讨论(0)
提交回复
热议问题