Domain Error = NSURLErrorDomain Code = -1017 "Operation could not be

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

    // 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:
    }
}
+4
5

- JSON:

kCFURLErrorCannotParseResponse = -1017

+6

HTTPMethod, , "NSURLErrorDomain Code = -1017", "request.HTTPMethod =" POST ".

.

+6

, GET (setHTTPBody)

+4

, -1017 - , http http-. , HTTP, "Authorization" : "qii2nl32j2l3jel" : Authorization : "1i2j12j". .

- :

NSMutableDictionary* newRequestHTTPHeader = [[NSMutableDictionary alloc] init];
[newRequestHTTPHeader setValue:authValue forKey:@"\"Authorization\""];
[newRequestHTTPHeader setValue:contentLengthVal forKey:@"\"Content-Length\""];
[newRequestHTTPHeader setValue:contentMD5Val forKey:@"\"Content-MD5\""];
[newRequestHTTPHeader setValue:contentTypeVal forKey:@"\"Content-Type\""];
[newRequestHTTPHeader setValue:dateVal forKey:@"\"Date\""];
[newRequestHTTPHeader setValue:hostVal forKey:@"\"Host\""];
[newRequestHTTPHeader setValue:publicValue forKey:@"\"public-read-write\""];

//the proper request is built with the new http headers.
NSMutableURLRequest* request2 = [[NSMutableURLRequest alloc] initWithURL:request.URL];
[request2 setAllHTTPHeaderFields:newRequestHTTPHeader];
[request2 setHTTPMethod:request.HTTPMethod];
0

PLease

Alamofire.request(method, "(URLString)" , parameters: parameters, headers: headers).responseJSON { response in }

post

parameters:parameters, encoding: .JSON

( GET POST, " " )

2, , .

["authentication_token" : "sdas3tgfghret6grfgher4y"]

.

0

All Articles