美文网首页
HTTPS证书

HTTPS证书

作者: 傲骨天成科技 | 来源:发表于2017-07-13 10:49 被阅读8次

import "ViewController.h"

@interface ViewController ()<NSURLSessionTaskDelegate>
@property (nonatomic, strong) NSURLSession *session;
@end

@implementation ViewController

  • (NSURLSession *)session {
    if (!_session) {
    NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
    _session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
    }
    return _session;
    }

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    }

  • (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    NSURL *url = [NSURL URLWithString:@"https://kyfw.12306.cn/otn/"];
    [[self.session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

      NSString *html = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
      NSLog(@"返回的字符串===%@",html);
    

    }] resume];
    }

pragma mark ---NSURLSessionTaskDelegate代理---

  • (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
    didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
    completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{

    // https工作原理
    // 1.判断身份验证方式是否是服务器验证方法
    if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {
    // 2.获取服务器证书
    NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
    // 3.信任服务器证书
    completionHandler(0,credential);
    }
    }
    @end

demo地址:https://github.com/SFOC/HTTPS-

相关文章

  • https证书

    转:http://www.jb51.net/article/96951.htm 申请链接:https://comm...

  • HTTPS证书

    付费证书 付费SSL证书国外排名中主要是Symantec, Entrust, Geotrust, Comodo, ...

  • HTTPS证书

    import "ViewController.h" @interface ViewController ()

  • 什么是HTTPS证书?HTTP与HTTPS的区别

    一、什么是HTTPS证书 HTTPS证书(即SSL证书)。HTTPS证书是颁发给标识互联网域名的数字证书,证书作用...

  • 配置https证书

    找到目录/alidata/server/nginx/conf 下的nginx.conf文件,文件内容如下 其实只要...

  • https证书安装

    证书安装 下载得到的 www.domain.com.zip 文件,解压获得3个文件夹,分别是Apache、IIS、...

  • 安装Https证书

    https(全称:Hyper Text Transfer Protocol over Secure Socket ...

  • 申请https证书

    做微信小程序时必须连接https. 不能http, 所以,自己测试的网站需要一个证书。 记下来申请步骤 去阿里云申...

  • Weex https证书

    h文件 m文件

  • https:自建证书

    苹果针对ATS逐渐收紧了政策,最近看了一些https的资料,自建证书主要用到openssl。根据苹果的政策,自建证...

网友评论

      本文标题: HTTPS证书

      本文链接:https://www.haomeiwen.com/subject/bahwhxtx.html