2

I am very new to IOS development, I wish to know if it possible to ignore ssl validation for "NSMutableURLRequest" class. If so please guide me. I have ignored the SLL validation through delegate by overriding

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

I wish to ignore the SLL validation without Delegate.

my code snippet

 NSString *username = _userName.text;
    NSString *password = _password.text;

    //HTTP Basic Authentication
    NSString *authenticationString = [NSString stringWithFormat:@"%@:%@", username, password];
    NSData *authenticationData = [authenticationString dataUsingEncoding:NSUTF8StringEncoding];
    NSString *authenticationValue = [authenticationData base64Encoding];

    //Set up your request
    NSMutableURLRequest *request1 = [[NSMutableURLRequest alloc] initWithURL:url];

                                                                             // Set your user login credentials
     [request1 setValue:[NSString stringWithFormat:@"Basic %@", authenticationValue] forHTTPHeaderField:@"Authorization"];

                                                                             // Send your request asynchronously
      [NSURLConnection sendAsynchronousRequest:request1 queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *responseCode, NSData *responseData, NSError *responseError) {
        if ([responseData length] > 0 && responseError == nil){
            //logic here
            NSString* newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
            NSLog(@"RESPONSE WITHOUT DELEGATE: %@",newStr);
            [[ApplicationStorage applicationStorage] setUserName:_userName.text];
            [[ApplicationStorage applicationStorage] setUserName:_password.text];
            [[ApplicationStorage applicationStorage] setUserName:_serverAdd.text];
        }}];

Thanks

Amith

Amith
  • 1,907
  • 5
  • 29
  • 48
  • Why not use AFNetworking ,This record on the website may help you [AFNetworking invalid ssl][1]. [1]: http://stackoverflow.com/questions/12967220/i-want-to-allow-invalid-ssl-certificates-with-afnetworking – KevinHM Jun 26 '15 at 14:38

1 Answers1

3

I think this has been answered before. You can try to add this to your AppDelegate.m, after @end

#if DEBUG

@implementation NSMutableURLRequest (NSURLRequestWithIgnoreSSL)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES;
}

@end

#endif
最白目
  • 3,505
  • 6
  • 59
  • 114