Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

objective c - I want to allow invalid SSL certificates with AFNetworking

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

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

The MyClient class code is below:

#import <Foundation/Foundation.h>
#import "AFNetworking.h"

@interface MyClient : NSObject

- (void)getHtml:(NSString *)path;

@end

#define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_

@implementation MyClient

- (void)getHtml:(NSString *)path
{
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"https://trusted.server.net"]];
    [httpClient getPath:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error = %@", error);
    }];
}

@end

I read below page and tried the macro but this doesn't work.

Self Signed certificate SSL · Issue #189 · AFNetworking/AFNetworking https://github.com/AFNetworking/AFNetworking/issues/189

Please help me...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In AFNetworking 2.0, you can use the following:

[AFHTTPRequestOperationManager manager].securityPolicy.allowInvalidCertificates = YES;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...