【发布时间】:2016-08-24 12:55:12
【问题描述】:
我正在使用 Ionic、Firebase、AngularJS 开发一个项目,并尝试从一个 magento2 项目中检索数据,该项目在 ubuntu 14.04 中使用 apache2 (http://localhost/magento2/) 在本地托管。
我解决了 CORS 错误,将其添加到我的 .htaccess 文件中
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Origin, Authorization, X-Requested-With, Content-Type, Accept"
</IfModule>
用于检索项目的 AngularJS product.js 文件
function getProducts() {
$http({
method: 'GET',
url: 'http://localhost/magento2/rest/V1/products/24-MB01',
headers: {
'Authorization': 'Bearer vbasmelg29r94nf8u10o6b8cxoko5rn9'
}
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log('[HTTP GET SUCCESS]', response);
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log('[HTTP GET ERROR]', response);
});
}
我使用 Postman 测试了这些 HTTP 调用并返回状态 200 OK。当我尝试通过角度使用时,我遇到了来自 chrome 的输出:
OPTIONS http://localhost/magento2/rest/V1/products/24-MB01 ionic.bundle.js:25000
XMLHttpRequest cannot load http://localhost/magento2/rest/V1/products/24-MB01. Response for preflight has invalid HTTP status code 400 :8100/#/product:1
拜托,你能帮帮我吗?
【问题讨论】:
-
您好,您是如何解决问题的?我已经放弃了对这个问题的投票。
标签: angularjs rest ionic-framework magento2