HTTPS Service is not working

后端 未结 2 525
误落风尘
误落风尘 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:43

    This is an issue with the website you're connecting to, not the code. If it does not have a known certificate, it will be treated as a security risk.

    0 讨论(0)
  • 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.)

    0 讨论(0)
提交回复
热议问题