AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
1.设置返回数据接收的类型
AFURLResponseSerialization.m
- (instancetype)init {
self = [super init];
if (!self) {
return nil;
}
//添加
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
return self;
}
2.请求限时
manager.requestSerializer.timeoutInterval = 15;
3.打印URL
找到AFURLRequestSerialization这个.m
找到requestBySerializingRequest: withParameters: error:这个方法
NSLog(@"URL: %@",mutableRequest.URL.absoluteString);
afnetwoking 3.0 默认 response为json, request 为 serieror;所以不用设置了。
response 一般都设置成json,因为后台返回数据为json。
request 一般不用设置,或设置成json,因为request不设置不报错,上传参数一般都是json格式
4.https
参考
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
manager.securityPolicy.allowInvalidCertificates = YES;
NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"文件名" ofType:@"cer"];
NSData *certData = [NSData dataWithContentsOfFile:cerPath];
manager.securityPolicy.allowInvalidCertificates = YES;
manager.securityPolicy.validatesDomainName = YES;
manager.securityPolicy.pinnedCertificates = [NSSet setWithObjects:certData, nil];