情况:
我正在处理一个从API接收数据的离子应用程序.
之前,API位于http://地址,一切正常.
然后我们将API移动到https://,它不再工作了.
或者,它仍然在浏览器中访问它,但不在手机(或仿真器)中.
我不知道可能是什么问题.在控制台日志中,我看到请求的状态为0.
它可能与白名单,标题或CORS有关.我已经尝试了几种方法,但没有工作.
白名单:
之前在config.xml中有这个白名单:
我试图以几种方式修改它,但是没有解决问题.
例如我试过:
和
API要求:
这是API请求的一个例子:
$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响应:
这是API响应的一个例子:
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 );
}
问题:
如何让API在HTTPS上工作?
如果这是一个CORS相关问题,我该如何在服务器端启用它?