How to do http.get request to a https server?

Hi,

I am not sure this is the right category, so if you think it should go somewhere else, let me know.

My Ionic 2 app works with regular http, but **seems ** not working with https. I am saying “seems” because I need to try other things, but in the mean time, I wanted to know if I need to do something different than this.http.get("https//:ipaddress/data.json") if I want to connect to that https server.

I am asking that because when using a regular web browser it will stop the communication and ask if I want to continue or not (Proceed to 10.97.222.210 (unsafe)). So, I guess I need to deal with that procedure. If so, how?

Thanks for your help.

You need a trusted SSL certificate otherwise the platform won’t allow the connection. Nor will your test browsers.

Otherwise you need to create a self signed certificate yourself - but it still wont be trusted and then do the following:

For IOS testing on device you need to add the following to the very bottom of the build AppDelegate.m file:

`@implementation NSURLRequest(DataController)

  • (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
    {
    return YES;
    }
    @end`

See this link: Link

And for in browser testing see this Link

1 Like

@dustinjsilk,

If I have that SSL certificate, where I will put it in my Ionic app directory/file?

The SSL certificate needs to be served by the https server.
To do that depends on your backend environment

Hi @dustinjsilk,

I just got more info about that certificate. To avoid the warning page, the server needs to get an IP within a certain range (ex: 10.224.5.21 to 10.224.5.26) or I need to map, in my hosts file, an IP address to xxx.servername.net. It is working on Windows or Linux, but how can I do it on a phone?

I would like to add something.

Now, when trying to access to the server from my phone, I get:

Javascript Alert
Access to “https://…” not allowed.

To me, it looks like a “Cross origin” issue. What do you think?

Hi,

Have you find a solution for your issue ?
I have the same question…

let’s try for Free SSL Certificate