NSURLConnection - Disable the authentication challenge response mechanism

后端 未结 2 794
心在旅途
心在旅途 2021-02-14 22:26

SITUATION

  • Using AFNetworking (NSURLConnection) to access my server API
  • The API needs Basic Authentication with token as username
2条回答
  •  无人共我
    2021-02-14 22:39

    You have a few of options to fully customize the authentication handling:

    1. Utilize setWillSendRequestForAuthenticationChallengeBlock: and setAuthenticationAgainstProtectionSpaceBlock: from class AFURLConnectionOperation and set corresponding blocks where you can tailor the mechanism you require.

      The headers contain documentation.

    2. Override connection:willSendRequestForAuthenticationChallenge: in a subclass of AFURLConnectionOperation. This will effectively override the complete authentication mechanism setup in AFNetworking.

    Note, that you cannot disable the "server validates client identity" authentication challenge -- this is part of the server. You MUST provide the correct credentials for the requested authentication method.

提交回复
热议问题