费话不说,直接代码:
+(AFURLSessionManager*) getSessionManager{
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
[config setTimeoutIntervalForRequest:HTTP_CONNECTION_TIMEOUT]; //设置请求时间
[config setTimeoutIntervalForResource:HTTP_TIMEOUT]; //设置请求时间
AFURLSessionManager* manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:config];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
///////////////////***************增加https验证******************//////////////////
NSString *certFilePath = [[NSBundle mainBundle] pathForResource:@"app" ofType:@"cer"];
NSData *certData = [NSData dataWithContentsOfFile:certFilePath];
NSSet *certSet = [NSSet setWithObject:certData];
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate withPinnedCertificates:certSet];
securityPolicy.allowInvalidCertificates = YES;//是否允许使用自签名证书
securityPolicy.validatesDomainName = NO;//是否需要验证域名,默认YES
manager.securityPolicy = securityPolicy;
///////////////////***************https验证结束******************//////////////////
return manager;
}
Info.plist中修改:
NSAllowsArbitraryLoads为true