I want to allow invalid SSL certificates with AFNetworking

前端 未结 13 621
南笙
南笙 2020-12-02 10:11

I want to allow invalid SSL certificates. My main code is below:

myClient = [[MyClient alloc] init];
[myClient getHtml:@\"/path/to/the/distination.html\"];
<         


        
相关标签:
13条回答
  • 2020-12-02 10:44

    In AFNetworking 2.0, you can use the following:

    [AFHTTPRequestOperationManager manager].securityPolicy.allowInvalidCertificates = YES;
    
    0 讨论(0)
  • 2020-12-02 10:44

    if you are using RestKit using

    client.allowsInvalidSSLCertificate = YES;
    

    won't work, instead do this:

    if you added rest kit manually to your project, click on RestKit.xcodeproj go to project > Build Settings > Preprocessor Macros

    and add _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_=1

    thats finished.

    0 讨论(0)
  • 2020-12-02 10:46

    I encountered the same problem and no one of the solutions that I read works.

    For me the only workaround is set the AFSecurityPolicy like this:

    AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
    securityPolicy.allowInvalidCertificates = YES;
    manager.securityPolicy = securityPolicy;
    

    I decided to reply although the question is old, maybe can help someone.

    0 讨论(0)
  • 2020-12-02 10:50

    To allow Invalid SSL Certificate with AFNetworking. Add the following line in AFURLConnectionOperation.h below #import Availability.h

    #define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_ 1
    
    0 讨论(0)
  • 2020-12-02 10:54

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest]; operation.securityPolicy.allowInvalidCertificates = YES;

    0 讨论(0)
  • 2020-12-02 10:56

    if you are using RestKit using

    client.allowsInvalidSSLCertificate = YES;
    

    won't work, instead do this:

    in your project, click on RestKit.xcodeproj go to project > Build Settings > Preprocessor Macros

    and add _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_=1

    thats finished.

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