Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 258
Feel Physics Avatar asked Oct 19 '12 04:10

Feel Physics


People also ask

What happens if SSL certificate is invalid?

An SSL certificate error occurs when the browser cannot verify the SSL certificates returned by the server. When the error happens, the browser blocks the website and warns the user that the website cannot be trusted as shown below. These warnings will negatively impact the user's trust in your website.


1 Answers

In AFNetworking 2.0, you can use the following:

[AFHTTPRequestOperationManager manager].securityPolicy.allowInvalidCertificates = YES; 
like image 89
titaniumdecoy Avatar answered Sep 21 '22 17:09

titaniumdecoy