The certificate for this server is invalid

前端 未结 9 1873
花落未央
花落未央 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:36

    That is a certificate error. you need to change your settings so that your program/os ignores the certificate, or add the url/certificate to a trusted list.

    Sorry that is authentication, certificate is authentication. I took a look, and I found this article.

    Not sure if it will resolve your issue, but it basically states, that they don't cover the case of connecting to a site with how a certificate in the documentation.

    http://www.cocoanetics.com/2009/11/ignoring-certificate-errors-on-nsurlrequest/

    0 讨论(0)
  • 2021-02-13 18:43

    This issue cannot be fixed with the way you are trying with blocks. you need to set delegates and implement the authentication challenge delegates to bypass the certificate validation. Best solution is to either create a right certificate (make sure it is not self-signed) or change the protocol to HTTP if you are fine with it.

    0 讨论(0)
  • 2021-02-13 18:46

    The webserver which you are using is asking for Server Trust Authentication, you need to properly respond with the appropriate action. You need to implement connection:willSendRequestForAuthenticationChallenge: delegate method and use SecTrustRef to authenticate it.

    More information can be found here:- https://developer.apple.com/library/ios/technotes/tn2232/_index.html

    This was my code to fix error:

    - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
    {
        NSURLProtectionSpace *protectionSpace = [challenge protectionSpace];
    
        id<NSURLAuthenticationChallengeSender> sender = [challenge sender];
    
        if ([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])
        {
            SecTrustRef trust = [[challenge protectionSpace] serverTrust];
    
            NSURLCredential *credential = [[NSURLCredential alloc] initWithTrust:trust];
    
                [sender useCredential:credential forAuthenticationChallenge:challenge];
        }
        else
        {
            [sender performDefaultHandlingForAuthenticationChallenge:challenge];
        }
    }
    
    0 讨论(0)
  • 2021-02-13 18:48

    In my case, this error occurred due to my system date. It was set as an old date, and the certificate is not effective from that old date. After correct the date, it works.

    0 讨论(0)
  • 2021-02-13 18:54

    Please check the following link.

    https://discussions.apple.com/thread/4912924?start=0&tstart=0

    0 讨论(0)
  • 2021-02-13 18:55

    you can't fix it with the way you are trying

    • either drop to CFNetworking to allow bad certs
    • use NSConnection with a delegate and an undoc'd method
    • use the private API you found

    all not good. CFNetwork would have to be OK for apple for now but the other 2 methods aren't even appstore-safe

    Better get the server fixed. Thats the easiest and CLEANEST

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