AFNetworking with request error code 999

旧时模样 提交于 2019-11-29 06:12:46

In my case iOS 9 SDK's "App transport security" cause AFNetworking error code : -999. If you're trying to reach a server that doesn't have a SSL add keys like screenshot below.

LittleBoat

In my case iOS 10 SDK's caused AFNetworking error code -999. If you're trying to reach a server that has SSL and you don't want to check it out, add some privacy Policy to Afnetworking

AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy.allowInvalidCertificates = YES;

[securityPolicy setValidatesDomainName:NO];

That's error -999, not 999. That is NSURLErrorCancelled. Your request has been cancelled before it can be completed.

Looking at your code, you aren't retaining the AFHTTPSessionManager *manager anywhere. This means that the manager will be disposed as soon as +simpleRequest returns. I'm guessing that this is what is cancelling your request.

You need to save the manager so that it lives for the full duration of the request. Save it in a property somewhere.

I noticed that your API endpoint indicates to a secure connection:

httpS://localhost:4443/api/v0/login/salt

Just try it just in case, maybe it repeats your situation.

In my case, this was a typo in the API manager code. Which from the part can be said is connected with App Transport Security Settings.

Just changed the protected protocol from httpS:// to http:// and the error:

NSURLErrorDomain Code = -999 "cancelled"

was gone and it all worked!

+And also if you had a similar problem. Be sure to discuss this with a backend specialist who deals with the server or API configuration for your application. This means that the server does not have valid security certificates. Perhaps you still need a secure connection. Or this specialist can again configure everything back from http:// to httpS://, and I'm not sure (did not check) whether this will work again when in the code you are already using a non-secure http:// connection.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!