2

I have a self signed certificate I'm using for development. I'm trying to request a webpage in my app.

Here's the code:

 NSURL* myUrl  = [[NSURL alloc] initWithString:url];
    NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];

    [self.webView loadRequest:myRequest];

..when the request goes through, my error method gets hit:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"Error : %@",error);
}

and writes this to the logger:

Error : Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be....

What can I do to "connect anyway", so that I can test this in development?

Jeff
  • 1,800
  • 8
  • 30
  • 54

1 Answers1

1

Using the below two methods we can allow self signed certificates

-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace;

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;

To find out how to achieve it using these methods visit here

Community
  • 1
  • 1
Durai Amuthan.H
  • 31,670
  • 10
  • 160
  • 241