2

I was testing iOS9 in my iPhone5 and I have realized that my API calls doesn't run. I made the call but it doesn't send anything to my backend.

This is my method:

-(void)placePostRequest:(NSString *)action withData:(NSDictionary *)dataToSend withHandler:(void (^)(NSURLResponse *response, NSData *data, NSError *error))ourBlock {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@", URL_API, action];
    NSLog(urlString);

    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    // Creamos el JSON desde el data
    NSError *error;

    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataToSend options:0 error:&error];

    NSString *jsonString;
    if (! jsonData) {
        NSLog(@"Got an error: %@", error);
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

        NSData *requestData = [NSData dataWithBytes:[jsonString UTF8String] length:[jsonString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];

        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
        [request setHTTPBody: requestData];

        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:ourBlock];
    }
}

HTTPResponse is nil and code 0:

enter image description here

This is what I received:

2015-06-15 13:40:48.176 myProject[291:33222] CFNetwork SSLHandshake failed (-9824)
2015-06-15 13:40:48.181 myProject[291:33222] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824)
EnriMR
  • 3,924
  • 5
  • 39
  • 59
  • Trace it, is this an HTTP link with transport security? What error do you get back? – Wain Jun 15 '15 at 11:36
  • I have updated my question with this info ;) I think it is related with security but I have not change anything in my backend or app code. – EnriMR Jun 15 '15 at 11:43
  • Don't set "Content-Length", let it set that for you. Where is "httpResponse" nil? Where's your handler block? – Marcus Adams Jun 15 '15 at 12:26

0 Answers0