objective c - Unable to load HTTPS pages in UIWebView with redirection [iOS 9] -


i trying load https:// webpage using uiwebview in ios 9+ , it's giving following error :

nsurlsession/nsurlconnection http load failed (kcfstreamerrordomainssl, -9802) cfnetwork sslhandshake failed (-9802)

i have tried various mentioned approaches of using nsurlconnection first handle authentication challenge using connection:willsendrequestforauthenticationchallenge: method.

although working fine direct requests, but (here actual problem begins) not working in case of webpages redirect page different domain.

so instance, load uiwebview call https://example.com , page redirects https://someothersecuredomain.com. connection fails , connection:willsendrequestforauthenticationchallenge: not called.

below implementation :

- (void)viewwillappear:(bool)animated {      [super viewwillappear:animated];      // load webview request url , parameters     nsmutableurlrequest* request = [[nsmutableurlrequest alloc] initwithurl:url];     [request sethttpbody:postbody];     [request sethttpmethod: @"post"];     [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"];      self.webview.delegate = self;     [self.webview loadrequest: request];      _baserequesturl = url; }  #pragma mark uiwebview delegate - (bool)webview:(uiwebview *)webview shouldstartloadwithrequest:(nsurlrequest *)request navigationtype:(uiwebviewnavigationtype)navigationtype {      if (![[request.url absolutestring] isequaltostring:[_failedrequest.url absolutestring]]) {          _failedrequest = request;         (void)[[nsurlconnection alloc] initwithrequest:request delegate:self];         return no;     }      return yes; }  #pragma mark - nsurlconnectiondatadelegate methods  -(void)connection:(nsurlconnection *)connection willsendrequestforauthenticationchallenge:(nsurlauthenticationchallenge *)challenge {     if ([challenge.protectionspace.authenticationmethod isequaltostring:nsurlauthenticationmethodservertrust]) {         nsurl *baseurl = [_failedrequest url];         if ([challenge.protectionspace.host isequaltostring:baseurl.host]) {             nslog(@"trusting connection host %@", challenge.protectionspace.host);             [challenge.sender usecredential:[nsurlcredential credentialfortrust:challenge.protectionspace.servertrust] forauthenticationchallenge:challenge];         } else             nslog(@"not trusting connection host %@", challenge.protectionspace.host);     }     [challenge.sender continuewithoutcredentialforauthenticationchallenge:challenge]; }  -(void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)presponse {      [connection cancel];     [self.webview loadrequest:_failedrequest]; }  - (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error {      nslog(@"connection error : %@", error); } 

and here connection error logged :

error domain=nsurlerrordomain code=-1200 "an ssl error has occurred , secure connection server cannot made." userinfo={nsunderlyingerror=0x138643250 {error domain=kcferrordomaincfnetwork code=-1200 "an ssl error has occurred , secure connection server cannot made." userinfo={nserrorfailingurlstringkey=https://secure.ccavenue.com/transaction/transaction.do?command=initiatetransaction, nslocalizedrecoverysuggestion=would connect server anyway?, _kcfnetworkcfstreamsslerrororiginalvalue=-9802, _kcfstreampropertysslclientcertificatestate=0, nslocalizeddescription=an ssl error has occurred , secure connection server cannot made., _kcfstreamerrordomainkey=3, nserrorfailingurlkey=https://secure.ccavenue.com/transaction/transaction.do?command=initiatetransaction, _kcfstreamerrorcodekey=-9802}}, nserrorfailingurlstringkey=https://secure.ccavenue.com/transaction/transaction.do?command=initiatetransaction, nserrorfailingurlkey=https://secure.ccavenue.com/transaction/transaction.do?command=initiatetransaction, nslocalizedrecoverysuggestion=would connect server anyway?, nslocalizeddescription=an ssl error has occurred , secure connection server cannot made.}

as per ios 9's app transport security, have added both domains list of exception domains in info.plist.

which :

<key>nsapptransportsecurity</key> <dict>     <key>nsallowsarbitraryloads</key>     <false/>     <key>nsexceptiondomains</key>     <dict>         <key>example.com</key>         <dict>             <key>nsincludessubdomains</key>             <true/>             <key>nstemporaryexceptionallowsinsecurehttploads</key>             <true/>             <key>nstemporaryexceptionminimumtlsversion</key>             <string>tlsv1.1</string>         </dict>         <key>secure.ccavenue.com</key>         <dict>             <key>nsincludessubdomains</key>             <true/>             <key>nstemporaryexceptionallowsinsecurehttploads</key>             <true/>             <key>nstemporaryexceptionminimumtlsversion</key>             <string>tlsv1.1</string>         </dict>     </dict> </dict> 

i stuck in , appreciated.

ps. tried these questions : question 1, question 2, question 3, question 4 , question 5


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -