我刚开始学习ios开发,正在尝试从一个使用ssl的网站获取图片,在用笔记本电脑浏览器连接到该网站时,会提示根证书不受信任,虽然我不是该网站的所有者,但我可以完全相信它。
self.eventImage.image = [UIImage imageWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString:imageUrl]]];
我遇到了这个错误:
NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9807)
我尝试通过启动iOS的web浏览器来向用户发送图片链接,当他们这样做时,会收到一条消息询问他们是否信任该链接,如果他们点击“是”,则图片将出现,但是我希望图片能够在应用程序内显示。
我也尝试使用Web View,但是它没有起作用。
大部分类似的问题都建议使用以下方法:
- (BOOL)connection:(NSURLConnection *)
connection canAuthenticateAgainstProtectionSpace:
(NSURLProtectionSpace *)protectionSpace {
return NO;
//return [protectionSpace.authenticationMethod isEqualToString:
// NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)
connection didReceiveAuthenticationChallenge:
(NSURLAuthenticationChallenge *)challenge {
NSString *imageUri =[self.detailItem objectForKey: @"image"];
NSArray *trustedHosts = [[NSArray alloc]initWithObjects:imageUri, nil];
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];
}
但是当我添加它们时,这两种方法从未被调用。
connection:...
方法被调用?你并没有使用NSURLConnection
。 - rmaddy