AFNetworking with request error code 999

error domain=nsurlerrordomain code=-999 "cancelled"
nserrorfailingurlstringkey
error domain=nsurlerrordomain code=-999 "cancelled" combine
nsurlerrordomain error code
nserrorfailingurlkey
the operation couldn t be completed nsurlerrordomain error -999
nsurlerrordomain error -999 react-native
wkreloadframeerrorrecoveryattempter

I'm new to objective-c and i'm having a hard time with a AFNetworking.

So the thing is that i want to make a simple POST request to a server who will send me back a salt. I'v make a simple app, in order to test my request but i don't understand why i'm getting the error code 999.

Here a sample of my code.

+ (void)simpleRequest; {
    NSURL *mailserver = [NSURL URLWithString:@"https://localhost:4443/"];

    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithBaseURL:mailserver];
    manager.securityPolicy.allowInvalidCertificates = TRUE;
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    NSDictionary *parameters = @{@"username": @"testtest"};

    [manager POST:@"api/v0/login/salt" parameters:parameters success:^(NSURLSessionDataTask *operation, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];
}

I' have link this code to a simple Button which's calling this function.

I have an other app, in ruby motion which's work fined with this function i can get the response without any error. But with this simple app i can't do any request, they all returned this error code 999.

Error: Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLKey=https://localhost:4443/api/v0/login/salt, NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=https://localhost:4443/api/v0/login/salt}

So i'm really wondering what i'm doing wrong, anyone can help me on this ? Thanks

EDIT:

Is it the good way for saving the manager in a property or am i doing something wrong ? If it's the good way, this seems to not work Thanks for the help

.h file

@property (nonatomic, retain) AFHTTPSessionManager *session;

.m file

@synthesize session;
- (IBAction)log:(id)sender {
NSURL *mailserver = [NSURL URLWithString:@"https://localhost:4443/"];

self.session = [[AFHTTPSessionManager alloc]initWithBaseURL:mailserver];
self.session.securityPolicy.allowInvalidCertificates = TRUE;
self.session.responseSerializer = [AFJSONResponseSerializer serializer];
self.session.requestSerializer = [AFJSONRequestSerializer serializer];
NSDictionary *parameters = @{@"username": @"testtest"};

[self.session POST:@"api/v0/login/salt" parameters:parameters success:^(NSURLSessionDataTask *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(NSURLSessionDataTask *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

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.

ios - AFNetworking with request error code 999, Hi, randomly my GET request from an https server fails with message: canceled and error code -999. 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.

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];

Requests fails with -999 error code · Issue #2895 · AFNetworking , AFNetworking / AFNetworking Error Domain=NSURLErrorDomain Code=-999 "cancelled" #3946 Even deployed apps see the error popped up, they weren't Successfully merging a pull request may close this issue. The only place NSURLErrorCancelled (-999 for NSURLErrorDomain) is set is in cancelConnection for AFURLConnectionOperation. I recommend breakpointing through code, and trying to understand how that cancel method was triggered. kcharwood closed this on Oct 19, 2015 josecostamartins commented on Oct 20, 2015

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.

Error Domain=NSURLErrorDomain Code=-999 "cancelled" · Issue , I'v make a simple app, in order to test my request but i don't understand why i'm getting the error code 999. Here a sample of my code. + (void)simpleRequest  The above is the same endpoint I'm trying to get the AFNetworking request working with. The message is only generated when the file is successfully processed on the api end. Below is the output of ls -lash on the server:-rw-r--r-- 1 vagrant vagrant 290190 Jan 26 15:26 Snow.jpg Below is the example code from the AFNetworking page:

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.

AFNetworking with request error code 999, AFNetworking with request error code 999. Question. I'm new to objective-c and i'​m having a hard time with a AFNetworking. So the thing is that i want to make a  Hi. i tried to set security policy. It seems its not working for me. All api request succeeded even if i do not attach certificate in application bundle.

[Original OP question may not mention Cordova but this link was very high in the search result when Googling this issue]

For my Cordova project (or similar), turns out it was a plugin issue. Make sure you're not missing any plugins and make sure they're installed properly without issue.

Easiest way to verify this is simply to start fresh by recreating the Cordova project (cordova create <path>) along with the required platforms (cordova platform add <platform name>) and add each plugin with the verbose flag (--verbose) so that you can see if anything went wrong in the console log while the plugin is being downloaded, added to project and installed for each platform (cordova plugin add cordova-plugin-device --verbose)

Recap: cordova create <path> cordova platform add <platform name> cordova plugin add cordova-plugin-device --verbose

AFNetworking with request error code 999, Ask questionsError Error Domain=NSURLErrorDomain Code=-999 "cancelled. Why Getting this error, Unable to AFNetworking/AFNetworking All api request succeeded even if i do not attach certificate in application bundle. I am writing  I ran into this issue while developing a proof of concept and our server didn't have the proper certificates. It seemed like most questions related to this was around using AFNetworking 1 and 2, and most of the answers did not work for me with AFNetworking 3, including modifying the .plist.

Error Error Domain=NSURLErrorDomain Code=-999 "cancelled , Error Domain=NSURLErrorDomain Code=-999 "cancelled" you're building the client inside the IBAction, and it's going out scope before the API call can finish. @misuqian Because we figured out AFNetworking doesn't support bidirection authentication, we can roll back to one-way authentication. Drag server certificate to project, configure securityPolicy as follow works for me.

Solved: -999 "cancelled" Error, iOS 11 HTTPS network request failure with self-signed cert Error Domain=​NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure You can dig into the AFNetworking code to work out how it interacts with the operation  URL Loading System Error Codes. These values are returned as the error code property of an NSError object with the domain “NSURLErrorDomain”. enum { NSURLErrorUnknown = -1, NSURLErrorCancelled = -999, NSURLErrorBadURL = -1000, NSURLErrorTimedOut = -1001, As you can see; -999 is caused by ErrorCancelled.

iOS 11 HTTPS network request failu…, Did I cancel some network request operation in operation queue trigged that? And how can I see AFNetworking with request error code 999. Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

Comments
  • It's showing that your URL is error...maybe should convert localhost to your IP address?
  • And sometime the params will be in the request body and that param field is nil: like https://localhost:4443/api/v0/login/salt?username=testtest
  • I just tried but it doesn't work, at least thanks for the help
  • In my case it should be a request like that 'localhost:4443/api/v0/login/salt', Which's work fined in my other app
  • i did some searched in Google and they said its because of previous one request hasn't complete and the other one sends , thus u get the Cancelled error
  • This should not be an accepted answer anymore. As of iOS 10, allowing arbitrary loads requires a review from Apple and specific permission to do so. The better answer is to use ATS to allow loads to HTTP locations by using exceptions. View this post, stackoverflow.com/questions/31254725/…, for the real solution to this problem.
  • A little more context, like where to assign this security policy, or whether it's a singleton, etc, would be helpful. This answer by itself isn't really enough.
  • Fwiw, the premise of this answer is useful -- setting the security policy on the session manger does help (at least in my case).
  • _sessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:_sessionConfiguration]; AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; securityPolicy.allowInvalidCertificates = YES; [securityPolicy setValidatesDomainName:NO]; _sessionManager.securityPolicy = securityPolicy;
  • I'm getting an error about AFSSLPinningModeNone being ambiguous (AFNetworking 3.1) (solved it using [AFSecurityPolicy defaultPolicy] which internally calls the same thing anyway).
  • This didn't entirely work, getting this warning now: "In order to validate a domain name for self signed certificates, you MUST use pinning".
  • I think i have correctly save the manager but it's still failing, did i have miss something ?
  • @xikimay then it's because the instance owning your property is deinitialised before the response gets back. A hack might be to call the manager within the block (through a Log()) for example.