AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
1.設(shè)置返回?cái)?shù)據(jù)接收的類型
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.請(qǐng)求限時(shí)
manager.requestSerializer.timeoutInterval = 15;
3.打印URL
找到AFURLRequestSerialization這個(gè).m
找到requestBySerializingRequest: withParameters: error:這個(gè)方法
NSLog(@"URL: %@",mutableRequest.URL.absoluteString);
afnetwoking 3.0 默認(rèn) response為json, request 為 serieror;所以不用設(shè)置了。
response 一般都設(shè)置成json,因?yàn)楹笈_(tái)返回?cái)?shù)據(jù)為json腔呜。
request 一般不用設(shè)置,或設(shè)置成json茫叭,因?yàn)閞equest不設(shè)置不報(bào)錯(cuò)正塌,上傳參數(shù)一般都是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];