我正在尝试访问亚马逊市场API。我收到以下错误,
无法加载http://completion.amazon.com/search/complete?search-alias=digital-text&client=amazon-search-ui&fb=1&mkt=1&q=trump:对预检请求的响应未通过访问控制检查:所请求的资源上没有'Access-Control-Allow-Origin'标头。
但是我已经在AWS rest API中传递了标头,并且启用了内核。
function getAmazonDataByKeyWord(keyword, callback) {
console.log('dhfajdkh');
const instance = axios.create({
baseURL: "http://completion.amazon.com",
headers: {
'Access-Control-Allow-Origin': 'http://localhost:9080',
"Access-Control-Allow-Headers": "Content-Type,Authorization",
"Access-Control-Allow-Methods": "PUT, GET, POST, DELETE, OPTIONS",
"Access-Control-Allow-Credentials": true
},
xhrFields: {
withCredentials: false
}
});
instance.defaults.headers["keyId"] = "AKIAI7VIL36475SPDBCA";
instance.defaults.headers["secretKey"] = "ggyvg0je2oYe84WButOYLIO4qy";
instance.defaults.headers["asoTag"] = "nerf0e-20";
instance.defaults.headers["keywordStatsQueue"] = new queue(1, Infinity);
instance.defaults.headers["keywordStatsAnalyzeQueue"] = new queue(1, Infinity);
instance.get("/search/complete?search-alias=digital-text&client=amazon-search-ui&fb=1&mkt=1&q=" + keyword).then(function (res) {
var result = {};
result.status = httpStatus.OK;
result.result = res.data;
console.log('res');
console.log(result);
callback(null, result);
}).catch(function (error) {
console.log(error);
});
}