HTTPS Service is not working

后端 未结 2 543
误落风尘
误落风尘 2020-12-21 14:24

I want to login by using web service.

My website is https based. I am using following tutorial.

http://agilewarrior.wordpress.com/2012/02/01/how-to-         


        
2条回答
  •  太阳男子
    2020-12-21 14:55

    What's happening is that your certificate is not valid (in the point of view of your app). If you want to take the risk, you can add the following code.

    - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
        return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    NSArray * trustedHosts = @[@"your domain"];
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
        if ([trustedHosts containsObject:challenge.protectionSpace.host])
            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
    
    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
    }
    

    So the certificate will be ignored. (remember to replace "your domain", with your domain.)

提交回复
热议问题