zoukankan      html  css  js  c++  java
  • iOS 绕过https证书验证 请求数据

    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 不需要处理,本身就处理了,查了下貌似是的:

  • 相关阅读:
    WCF系列(七) WCF安全系列(二) netTCPBinding绑定之Transport安全模式
    WCF系列(六) WCF安全系列(一) basicHttpBinding
    Convert .Net Program To Mono
    Adware:Win32/FastSaveApp 清除
    Python Http Get Post请求
    Python正则表达式应用示例
    Basic4android 使用Basic开发Android应用
    Decode Android AndroidManifest.xml file via C#
    Python工作记录
    趣文:程序员/开发人员的真实生活
  • 原文地址:https://www.cnblogs.com/air-liyan/p/6407011.html
Copyright © 2011-2022 走看看