12

I am trying to call my url using

NSDictionary *landingDetails=[appDelegate landingPage];

        NSString *devinf=[UIDevice currentDevice].systemVersion;
        NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

        NSMutableDictionary *reqDict=[NSMutableDictionary dictionary];
        [reqDict setObject:@"refillByScan" forKey:@"appId"];
        [reqDict setObject:@"extest1" forKey:@"affId"];
        [reqDict setObject:[landingDetails objectForKey:@"token"] forKey:@"token"];
        [reqDict setObject:@"0124400-59382" forKey:@"rxNo"];//medication or prescription id
        [reqDict setObject:@"appName://handleControlFromScanRefill" forKey:@"appCallBackScheme"];
        [reqDict setObject:@"callBackAction" forKey:@"appCallBackAction"];
        [reqDict setObject:@"chkExpRx" forKey:@"act"];
        [reqDict setObject:@"" forKey:@"trackingId"];
        [reqDict setObject:devinf forKey:@"devinf"];
        [reqDict setObject:appVersion forKey:@"appver"];

        NSString *landingUrl=[landingDetails objectForKey:@"landingUrl"];//my url
        request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:landingUrl]];
        NSString *jsonRequest = [reqDict JSONRepresentation];
        NSLog(@"jsonRequest is %@", jsonRequest);
        NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];

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

        con=[[NSURLConnection alloc]initWithRequest:request delegate:self];
        [con start];

I am getting this error in my log

2013-11-27 19:43:30.754 WallGreen[5594:3a03] CFNetwork SSLHandshake failed (-9806)
2013-11-27 19:43:31.273 WallGreen[5594:3a03] CFNetwork SSLHandshake failed (-9806)
2013-11-27 19:43:31.799 WallGreen[5594:3a03] CFNetwork SSLHandshake failed (-9806)
2013-11-27 19:43:31.800 WallGreen[5594:3a03] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806)
Jay Gajjar
  • 2,661
  • 2
  • 21
  • 35
  • Is the URL's SSL/TLS certificate self-signed or signed by a Certificate Authority listed in the System Keychain? OpenSSL includes an excellent s_client tool for debugging these kinds of problems: http://www.openssl.org/docs/apps/s_client.html – Graham Miln Nov 27 '13 at 14:23
  • i think its ssl/tls certified – Jay Gajjar Nov 28 '13 at 08:56
  • 1
    http://stackoverflow.com/questions/19922717/how-to-handle-cfnetwork-sslhandshake-failed-in-ios – Chander Shakher Ghorela - Guru Feb 04 '14 at 18:35
  • I am also experiencing this issue, in an app that has worked in the past. I am issuing an HTTP POST to a URL using HTTPS on port 443 using `NSURLConnection`. I am trying to connect to a newly configured server, so I think the configuration has something to do with this. My app never gets the chance to provide authentication challenge information in `connection:willSendRequestForAuthenticationChallenge:`. There seems to be very little information on -9806. Networking and internet access is all working fine. – Rick Morgan Feb 18 '14 at 15:15
  • I'm facing similar issue only while debugging otherwise it's working fine. – Jayprakash Dubey Oct 20 '14 at 08:54
  • I actually had the same issue. Please see my answer in this question: http://stackoverflow.com/questions/19922717/how-to-handle-cfnetwork-sslhandshake-failed-in-ios/32246010#32246010 – OhadM Aug 27 '15 at 09:48

3 Answers3

5

FWIW: I got the same error number and it was due to an expired certificate, so this is another potential source for the issue.

Arkaaito
  • 7,347
  • 3
  • 39
  • 56
  • 4
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Stonz2 Oct 10 '14 at 18:51
  • 1
    I'm not sure I fully understand this comment. Are you saying that "it might be due to an expired certificate" is not an answer because it's not 100% certain? Or that it needs details on how to generate a new certificate if an expired one is indeed the problem (details which will vary based on the issuing CA)? Any details you can offer about specific deficiencies in my answer would be appreciated. – Arkaaito Oct 11 '14 at 21:59
  • I have this error with invalid certificate (host name in certificate didn't match). – Lukasz 'Severiaan' Grela Oct 27 '14 at 08:31
1

There is a bug on iOS 8 when using a certificate with hash function SHA512, better use the SHA256. I stuck with this error for weeks.

sarge
  • 183
  • 2
  • 6
1

Normally when I get CFNetwork SSLHandshake failed -(*) Its because of my local wifi network (device is connected to network but not the internet)

Try it again on another network (3G is the quickest solution for me)

Usman Javed
  • 2,437
  • 1
  • 17
  • 26