Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does PhoneGap Support HTTPS ajax requests?

Tags:

ajax

cordova

I have an application where the html/javascript code executes fine in a standalone browser safari, but when the ajax calls are executed in PhoneGap, they all fail with the Network Error 101.

I am requesting XML documents

like image 303
Aaron Saunders Avatar asked Aug 24 '10 20:08

Aaron Saunders


2 Answers

Yes.

BUT, it does not gracefully handle certificate errors with the HTTPS protocol. I ended up writing my own code to establish the initial connection with the server and ignore the cert errors

here is the code http://blog.clearlyinnovative.com/post/1012434483/phonegap-and-iphone-development

like image 104
Aaron Saunders Avatar answered Nov 16 '22 08:11

Aaron Saunders


Phonegap does support HTTPS ajax requests, but like Aaron mention it does not gracefully handle certificate errors. In my case, we have valid certs in our production environment; but for our dev environment we overrode one of the NSUrl methods:

@implementation NSURLRequest (IgnoreSSL)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES;
}

@end

This has been tested with phonegap 1.7(and 1.9) and it worked well. You can put this code in your MainViewController.m.

Note that I recommend this code only for development environment. This most likely will not be accepted by the app store; since we are overriding a private api. Just use valid certs in production.

like image 44
Aki Avatar answered Nov 16 '22 08:11

Aki