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]);
        }];
  • 相关阅读:
    Docker 系列(四):Docker 容器数据卷简单使用
    【QML 动态对象】使用JS中的语句动态创建和销毁组件
    【QML 动态对象】Loader动态加载组件
    vue-cli2.0全局使用sass变量
    两边+居中 布局
    跳转子路由后左侧菜单跳转为空白页,路由地址出错
    el-tree可搜索单选
    el-tree固定高度加滚动条
    前端 权限控制 方式
    综合分析类
  • 原文地址:https://www.cnblogs.com/OrangesChen/p/5041865.html
Copyright © 2011-2022 走看看