Angular 2 HTTPS request

Gaurav Ram picture Gaurav Ram · Sep 27, 2016 · Viewed 37.4k times · Source

How to configure and make a https request from angular 2?

Couldn't find any resources on it.

Can please someone guide me here?

Thank you.

Answer

Ahmed Elkoussy picture Ahmed Elkoussy · May 7, 2018

Just in case someone else is trying to do this

You should make the https calls just like the normal http calls but you have to ensure that your browser trust the certificate that is used by the backend APIs & that your browser can connect to this api.

Note:

It might give timeout error in YARC or REST clients so you should try a simple GET request directly in the browser (i.e: navigate to https get request)

For example, if we have this API

https://testDomain.com:7001/getCountries

Try to make a get request to this url by navigating to it in the browser, if you are testing locally or in UAT, your certificate might not be fully trusted in the browser automatically, so you have to tell chrome that you trust this website & go there (proceed to this website)

If you can successfully call this get request in the browser:

Then you can call the https apis just as you call normal http (with full correct URL having the https & the port number) as per the below resources:

1- Angular httpClient guide

2- You can also check out this excellent guide on making http calls in Angular 5