zoukankan      html  css  js  c++  java
  • https访问证书问题

    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]);
        }];
  • 相关阅读:
    函数式编程
    scala 有 + 运算符吗?
    使用 Idea 打 scala程序的 jar 包
    相见恨晚的 scala
    半夜思考,为什么 String 具有不变性
    我的常用
    DataTable学习笔记
    Js 操作cookie
    嵌套的 ajax 请求
    Jquery插件收集【m了慢慢学】
  • 原文地址:https://www.cnblogs.com/OrangesChen/p/5041865.html
Copyright © 2011-2022 走看看