我正在尝试从安全的休息服务中获取数据。我跟随许多其他帖子
How to use NSURLConnection to connect with SSL for an untrusted cert?
但在我的情况下,didReceiveAuthenticationChallenge和canAuthenticateAgainstProtectionSpace都没有被调用。
如果你能解决问题或者给我一些很好的例子来打电话给安全的休息服务,请提供帮助。
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];
}
答案 0 :(得分:0)
可能与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];
}
答案 1 :(得分:0)
&