user1141351 user1141351 - 1 year ago 438
Objective-C Question

Error Domain=NSURLErrorDomain Code=-1017 "The operation couldn’t be

I just started ios development and I'm trying to exchange data with my api. When I'm doing POST requests everything is going fine but when I'm trying to do a GET request I get the following error:

Error Domain=NSURLErrorDomain Code=-1017 "The operation couldn’t be
completed. (NSURLErrorDomain error -1017.)" UserInfo=0x145a2c00
_kCFStreamErrorCodeKey=-1, NSErrorFailingURLKey=,
_kCFStreamErrorDomainKey=4, NSUnderlyingError=0x145b21d0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error

Could someone explain what's going wrong and how I can 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];

// The body
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) {
//Gives my error
else {
// do something:

Answer Source

You have something wrong with your JSON parameters:

kCFURLErrorCannotParseResponse = -1017

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download