abi*_*son 6 amazon amazon-s3 nsurlconnection afnetworking
我正在尝试显示存储在Amazon S3 Bucket上的图像.URL类似于https://s3.amazon.com/..../test.jpg.每当我在iPhone模拟器上执行此操作时,图像都会正确显示.但是,如果我在实际设备上测试它,我会继续:
错误域= NSURLErrorDomain代码= -1202"此服务器的证书无效.您可能连接到假冒"s3.amazonaws.com"的服务器,这可能会使您的机密信息面临风险." UserInfo = 0x20007030 {NSErrorFailingURLStringKey = https://s3.amazonaws.com/.../test.jpeg,NSLocalizedRecoverySuggestion =您是否还要连接到服务器?,NSErrorFailingURLKey = https://s3.amazonaws.com/. ../test.jpeg,NSLocalizedDescription =此服务器的证书无效.您可能正在连接到假装是"s3.amazonaws.com"的服务器,这可能会使您的机密信息面临风险.,NSUnderlyingError = 0x20014d40"此服务器的证书无效.您可能正在连接到服务器假装是"s3.amazonaws.com",可能会使您的机密信息面临风险.",NSURLErrorFailingURLPeerTrustErrorKey =}
有任何想法吗?!
谢谢!
小智 12
我从S3获得相同的证书错误,并发现将此添加到NSURLConnectionDelegate修复了问题:
-(void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] &&
[challenge.protectionSpace.host hasSuffix:@"example.com"])
{
// accept the certificate anyway
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
else
{
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
}
Run Code Online (Sandbox Code Playgroud)
注意:您需要将"example.com"更改为您信任的域,或使用比"hasSuffix"更复杂的机制.
仅供参考Apple Technote TN2232"HTTPS服务器信任评估"详细介绍了证书被拒绝的原因以及如何处理该证书:https: //developer.apple.com/library/ios/technotes/tn2232/_index.html
由于戈登·亨里克森回答这个在/sf/answers/142367641/,但使用的是旧的API.
| 归档时间: |
|
| 查看次数: |
8030 次 |
| 最近记录: |