I just started developing ios and I am trying to exchange data with api. When I execute POST requests, everything goes fine, but when I try to execute a GET request, I get the following error:
Domain Error = NSURLErrorDomain Code = -1017 "Operation could not be completed. (NSURLErrorDomain -1017.)" UserInfo = 0x145a2c00 {NSErrorFailingURLStringKey = http://myAPI.com/ , _kCFStreamErrorCodeKey = -1, NSErrorFail .com , _kCFStreamErrorDomainKey = 4, NSUnderlyingError = 0x145b21d0 "The operation could not be completed. (kCFErrorDomainCFNetwork error -1017.)"}
Can someone explain what is happening and how can I fix it?
My request:
-(void)hitApiWithURL:(NSString*)url HTTPMethod:(NSString*)HTTPMethod params:(NSDictionary*)params successBlock:(successTypeBlock)success failureBlock:(errorTypeBlock)failure{
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];
[sessionConfig setHTTPAdditionalHeaders:@{@"Content-type": @"application/json"}];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:HTTPMethod];
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error];
[request setHTTPBody:jsonData];
NSURLSessionDataTask *dataTaks = [session dataTaskWithRequest:request];
[dataTaks resume];
NSLog(@"dataTask started");
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
didCompleteWithError:(NSError *)error {
if (error) {
}
else {
}
}