首页 > 移动平台 > 详细

iOS 绕过https证书验证 请求数据

时间:2017-02-16 22:13:07      阅读:399      评论:0      收藏:0      [点我收藏+]
HTTPS和HTTP:
 1、https协议需要到ca申请证书,一般免费证书很少,需要交费。
 2、http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议。
 3、http和https使用的是完全不同的连接方式,用的端口也不一样
 4、http的连接很简单,是无状态的;HTTPS协议是由SSL HTTP协议构建的可进行加密传输、身份认证的网络协议,比http协议安全。

因为项目需要调试,公司自己弄了个证书验证,所有需要在请求数据的时候绕过验证,在网上搜了下,最后代码贴上

- (void)session{
    
    NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:Nil];
    NSURLSessionTask *task = [session dataTaskWithURL:[NSURL URLWithString:@"https://114.55.231.139/"] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        //
        
        NSLog(@"error:%@",error);
        NSLog(@"data:%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
    }];
    [task resume];
    
    
}
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler{
    if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
        if([challenge.protectionSpace.host isEqualToString:@"114.55.231.139"]){
            NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
            completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
        } else {
            completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
        }
    }
}

有说AFNetworking 不需要处理,本身就处理了,查了下貌似是的:
技术分享

 

iOS 绕过https证书验证 请求数据

原文:http://www.cnblogs.com/air-liyan/p/6407011.html

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