創建一個MEAN堆棧應用程序,我有一個角度組件,在頁面加載時向亞馬遜產品API發出請求。我正在本地運行和測試本地主機(節點/快遞後端)。角度CORS與亞馬遜產品API
這裏是我的組件的基本要求代碼:
getAmazonTackle(amz:amazonservice) {
var req:Object = {
method: this.amazonservice.Method,
url: this.amazonservice.Endpoint,
headers: {
//"Access-Control-Allow-Origin":"*"
},
data: this.amazonservice.Data,
withCredentials: false
}
console.log(JSON.parse(JSON.stringify(req)));
this.$http(req).then(
function(response) {
console.dir('The response: '+response);
},
function(response) {
console.dir(response);
console.dir('The error:'+response);
}
)
}
當我沒有Access-Control-Allow-Origin
頭,訪問我呈現在下面的瀏覽器頁面Chrome的開發者控制檯:
XMLHttpRequest cannot load http://webservices.amazon.com/onca/xml?.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3000' is therefore not allowed access.
當我添加了Access-Control-Allow-Origin
頭,我收到以下內容:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3000' is therefore not allowed access.
我想確定的是,如果我這樣做不正確,或者如果亞馬遜API不支持CORS。