3

I am facing the error while making HTTPS request :-

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813).

I did some google and there were some solutions mentioned to by pass the ATS (Application Transport Security) by mentioning the following key in my project info plist file. This is the issue in iOS9 and above.

**Keys are :-

key :- NSAppTransportSecurity

value : -NSAllowsArbitraryLoads : true**

I have tried this solution. But i am still facing the same issue all the time. I am stuck in this. Can anyone please help me ?

Jigar Tarsariya
  • 3,189
  • 3
  • 14
  • 38
i_Intiution
  • 228
  • 4
  • 16
  • Apparently this is happening in ios version > 10. For fix it follow the next link https://stackoverflow.com/questions/31249559/react-native-xmlhttprequest-request-fails-if-ssl-https-certificate-is-not-vali – jose920405 Jul 12 '17 at 22:33

2 Answers2

0

You have to add just the NSAllowsArbitraryLoads key to YES in NSAppTransportSecurity dictionary in your info.plist file.

enter image description here

Bhumika
  • 876
  • 7
  • 20
  • Thanks for your reply @Bhumika. But i have tried already this solution. It is not working. – i_Intiution Jun 17 '16 at 10:32
  • It can be dangerous. Also Apple also says that using this solution will trigger app review [source](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW59) – franiis Oct 28 '16 at 06:38
0

I have fixed my issue by implementing the authentication challenge delegate method of NSURLConnction.

Following implementation fixed my issue.

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
       NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
      [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];

      [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
Bhumika
  • 876
  • 7
  • 20
i_Intiution
  • 228
  • 4
  • 16