Ignoring certificate errors with NSURLConnection

前端 未结 6 1391
臣服心动
臣服心动 2020-11-30 08:42

I am getting this error

The certificate for this server is invalid. You might be connecting to a server
that is pretending to be \"server addres goes here\"         


        
6条回答
  •  天涯浪人
    2020-11-30 09:27

    You could simply ignore the invalid certificate if you are not sending any sensitive information. This article describes how you could do that. Here is an example implementation by Alexandre Colucci for one of the methods described in that article.

    Essentially you want to define a dummy interface just above the @implementation:

    @interface NSURLRequest (DummyInterface)
    + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
    + (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;
    @end
    

    And before you call sendSynchronousRequest, invoke the private method you defined in the dummy interface:

    [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[URL host]];
    

提交回复
热议问题