NSURLConnection - Disable the authentication challenge response mechanism

后端 未结 2 792
心在旅途
心在旅途 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:54

    Try this.

    - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
    {
        SecTrustRef trust = challenge.protectionSpace.serverTrust;
        NSURLCredential *cred;
        cred = [NSURLCredential credentialForTrust:trust];
        [challenge.sender useCredential:cred forAuthenticationChallenge:challenge];
    }
    

提交回复
热议问题