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