afn

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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容