gpt4 book ai didi

iphone:不调用 didReceiveAuthenticationChallenge 和 canAuthenticateAgainstProtectionSpace 以提供安全的 Restful 服务

转载 作者:太空宇宙 更新时间:2023-11-03 15:05:04 24 4
gpt4 key购买 nike

我正在尝试从安全的 restful 服务中获取数据。我关注许多其他帖子以及

How to use NSURLConnection to connect with SSL for an untrusted cert?

但在我的例子中,没有调用 didReceiveAuthenticationChallenge 和 canAuthenticateAgainstProtectionSpace。

如果您能解决问题或提供一些调用安全 Restful 服务的好例子,请提供帮助。

 NSURL *url = [NSURL URLWithString:@"https://76.69.53.126:8443/jaxrs/tdgateway/getCountries"];


NSError * error = nil;
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
[ NSURLConnection sendSynchronousRequest: urlRequest returningResponse: nil error: &error ];

NSLog(@"This is %@",url);




- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
NSLog(@"This is canAuthenticateAgainstProtectionSpace");
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSLog(@"This is didReceiveAuthenticationChallenge");
[[challenge sender] cancelAuthenticationChallenge:challenge];
}

最佳答案

它可能与 NSURLAuthenticationMethodServerTrust 不同,因此请先尝试一下:

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return YES;
}

您不应该立即取消它:

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSLog(@"This is didReceiveAuthenticationChallenge");
[[challenge sender] cancelAuthenticationChallenge:challenge];
}

关于iphone:不调用 didReceiveAuthenticationChallenge 和 canAuthenticateAgainstProtectionSpace 以提供安全的 Restful 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11313061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com