首页 > Web开发 > 详细

https访问证书问题

时间:2015-12-12 21:47:06      阅读:675      评论:0      收藏:0      [点我收藏+]

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

在info.plist中添加

NSAppTransportSecurity   NDictionary

NSAllowsArbitraryLoads  Boolean  YES
技术分享

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9807)

遵守NSURLConnectionDelegate NSURLConnectionDataDelegate协议

#pragma mark-NSURLConnectionDelegate
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
    NSLog(@"处理证书");
    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
    } else {
        [challenge.sender cancelAuthenticationChallenge:challenge];
    }
}

#pragma mark-NSURLConnectionDataDelegate
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

{
//请求获取的数据 NSLog(
@"%@", [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil]); }
  [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://chanyouji.com/api/trips/featured.json?page=1"]] queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse * response, NSData * data, NSError * connectionError) {
        NSLog(@"%@", [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil]);
    }];

 

https访问证书问题

原文:http://www.cnblogs.com/OrangesChen/p/5041865.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!