I'm new to objective-c, and it's hard for me to spend time with AFNetworking.
So, I want to make a simple POST request to the server, which will send me salt. I am making a simple application to check my request, but I do not understand why I am getting error code 999.
Here is an example 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 associate this code with a simple button that calls this function.
I have another application, in ruby ββmovement, which works with this function, I can get an answer without any errors. But with this simple application, I canβt fulfill any request, they all returned this error code 999.
Error: Domain error = NSURLErrorDomain Code = -999 "canceled" UserInfo = {NSErrorFailingURLKey = https: // localhost: 4443 / api / v0 / login / salt , NSLocalizedDescription = canceled, NSErrorFailingURLStringKey = https: // localhost: 4443 / api / v0 / login / salt }
So I'm really curious what I'm doing wrong, can anyone help me with this? Thanks
EDIT:
Is this a good way to keep the manager in the property, or am I doing something wrong? If this is a good way, this doesn't seem to 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); }];