//
// ViewController.m
// AFN之HTTPS
//
// Created by 唐帅 on 14/7/3.
// Copyright © 2014年 ItTS. All rights reserved.
//
#import "ViewController.h"
#import "AFNetworking.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self loadData];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)loadData
{
// 创建网络请求mansger
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
// 使AFN支持HTTPS请求 : 2.5.4之前
// manager.securityPolicy.allowInvalidCertificates = YES;
// 使AFN支持HTTPS请求 : 2.6.1以后
manager.securityPolicy.validatesDomainName = NO;
// 修改AFN默认支持接收的文本类型
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html" ,nil];
// 修改AFN默认处理数据的方式 : 设置成只返回原始的二进制数据,程序猿自己反序列化
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
// 网络请求地址
NSString *URLStr = @"https://mail.itcast.cn";
[manager GET:URLStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
// 反序列化
NSString *html = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"%@",html);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"出错 %@",error);
}];
}
@end