关于AFNetworking 2.0的报错问题

虽然现在AFN已经出到3.0,但是有些封装等等原因有可能还在用着2.0

那么2.0在请求时候需要注意的地方结合iOS9 需要进行修改的地方都有哦那些呢?

首先iOS9众所周知的一件事就是https相关

如果你的服务器还没支持那么按照网上的教程来在info.plist里面加上如下键值对


这个就可以任性的加载http的请求了,不多说,网上到处是。

当遇到-1016,-3840时候的问题,不管你要发送的是http还是https的请求

manager.responseSerializer = [AFHTTPResponseSerializer serializer];

序列化的问题,当出现的错误提示是,有的类型接受不了的时候,这个就要设置接受的类型了

self.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/plain", @"text/javascript", @"text/json", @"text/html", nil];

[self.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];

重点来说一下的问题-1012

当你翻遍网上所有的经验时候还是被-1012卡住的时候,而恰巧你又是发送的https的请求的时候

来到AFN的源码里我们需要做的一件事就是AFN的安全认证去掉

- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust

forDomain:(NSString *)domain

{

//    if (domain && self.allowInvalidCertificates && self.validatesDomainName && (self.SSLPinningMode == AFSSLPinningModeNone || [self.pinnedCertificates count] == 0)) {

// https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/OverridingSSLChainValidationCorrectly.html

//  According to the docs, you should only trust your provided certs for evaluation.

//  Pinned certificates are added to the trust. Without pinned certificates,

//  there is nothing to evaluate against.

//

//  From Apple Docs:

//          "Do not implicitly trust self-signed certificates as anchors (kSecTrustOptionImplicitAnchors).

//          Instead, add your own (self-signed) CA certificate to the list of trusted anchors."

//        NSLog(@"In order to validate a domain name for self signed certificates, you MUST use pinning.");

//        return NO;

//    }

如上所示的注释掉,好了,发送的https可以访问了,当然这个方法也是对于AFN2.0而言的

不到没有办法的时候不要这么搞。

如果你有什么好的办法欢迎交流,欢迎告知。

你可能感兴趣的:(关于AFNetworking 2.0的报错问题)