The certificate for this server is invalid

前端 未结 9 1833
花落未央
花落未央 2021-02-13 18:04

I know that if I use following nsurlconnectiondelegate it will be fixed

– connection:willSendRequestForAuthenticationChallenge: – connection:canAuthenti

相关标签:
9条回答
  • 2021-02-13 18:55

    Try this.

    Initiate your session using custom session config as shown below:

    let session = URLSession(configuration: URLSessionConfiguration.ephemeral,
                                     delegate: self,
                                     delegateQueue: nil)
    

    Implement the following delegate callback method:

    public func urlSession(_: URLSession, task _: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        guard let serverTrust = challenge.protectionSpace.serverTrust else {
            return completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil)
        }
        return completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
    }
    
    0 讨论(0)
  • 2021-02-13 18:56

    If you are using AFNetworking, you can use this code:

    (Just as a temp client-side solution!)

    AFHTTPSessionManager * apiManager = [AFHTTPSessionManager initWithBaseURL:[NSURL URLWithString:baseURL];
    AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
    policy.allowInvalidCertificates = YES;
    apiManager.securityPolicy = policy;
    
    0 讨论(0)
  • 2021-02-13 19:00

    In my case, this error occurred due to my firewall blocked the required url. it's worked fine after removing firewall restrictions

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