Domanda

I'm using [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)] to pull data from a web service, but the web server has a self-issued certificate, causing this error to appear:

SSL Error

Error displayed using:

NSAlert *a = [NSAlert alertWithError:error];
[a runModal];

Is there any way to ignore this error and continue anyway?

È stato utile?

Soluzione

Following the instructions in the linked question, I defined a dummy interface for NSURLConnection:

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

And called the method before creating the request:

[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

This suppressed the error about the certificate being invalid.

Altri suggerimenti

This may be rejected by Apple. Use the proper implementation of NSConnectiondatadelegate:

see a way around it: Stackoverflow response to similar question

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top