THE SITUATION:
I am working on a Ionic app that receive data from an API.
Before, the API was on http:// address and everything was working fine.
Then we have moved the API to https:// and it's not working anymore. Or well, it is still working accessing it in the browser, but not in the phone (or emulator).
I am not sure what may be the problem. In the console log I see that the status of the request is 0.
It may be related with the whitelist, with the headers, or with CORS. I have tried several approaches but none worked.
WHITELIST:
Before in the config.xml there was this whitelist:
<allow-navigation href="http://*/*" />
I have tried to modify it in several ways but that didn't fix the problem. For example I have tried:
<allow-navigation href="https://*/*" />
and
<allow-navigation href="*" />
API REQUEST:
This is one example of API request:
$http.get( 'https://MY_DOMAIN.com/mobile/list_mobile_project/' ,{},{"headers" : {"Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8" }})
.success(function(data, status, headers, config)
{
// code
}).
error(function(data, status, headers, config)
{
console.log('Error with the API list_mobile_project');
console.log(data);
console.log(status);
console.log(headers);
console.log(config);
});
API RESPONSE:
And this is an example of API response:
public function list_mobile_project()
{
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
// code
echo json_encode( $project_list );
}
THE QUESTION:
How to get the API working also on HTTPS?
If it is a CORS related problem, how can I enable it on server side?