Tuesday, 20 January 2015

Call https webservice thourgh iOS code; NSURLConnection to connect with SSL for an untrusted cert?

If yor are getting this error
NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813);



Then it can resolve very easily by using NSURLRequest category concept;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////        NSURLRequest+HTTPS.h     /////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#import 

@interface NSURLRequest (NSURLRequest_HTTPS)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;

//+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;

@end

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////        NSURLRequest+HTTPS.m     /////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#import "NSURLRequest+HTTPS.h"

@implementation NSURLRequest (NSURLRequest_HTTPS)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host{
    return YES;
}
//
//+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host {
//    
//}

@end


http://stackoverflow.com/questions/24134652/https-get-request-certificate-error-xcode
http://stackoverflow.com/questions/933331/how-to-use-nsurlconnection-to-connect-with-ssl-for-an-untrusted-cert/2033823#2033823

No comments:

Post a Comment