我一直在尝试使用axios向国家公园服务API发出GET请求,已经尝试了几种方法将我的API密钥设置在请求头中,但都没有成功。非常感谢任何帮助。
我已经尝试过:
axios.defaults.headers.common['Authorization'] = "MY-API-KEY";
axios.get('https://developer.nps.gov/api/v0/parks?parkCode=yell')
.then((resp) => {
console.dir(resp);
});
并且
let config = {'Authorization': 'MY-API-KEY'};
axios.get('https://developer.nps.gov/api/v0/parks?parkCode=yell', config)
.then((resp) => {
console.dir(resp);
});
两个请求都返回401。当我在Postman中发送GET请求时,它能够工作,我在key字段中输入Authorization,在value字段中输入我的API密钥。
谢谢。
OPTIONS https://developer.nps.gov/api/v0/parks?parkCode=yell 401 (OK)
。 - jcarapialocalhost/:1 XMLHttpRequest cannot load https://developer.nps.gov/api/v0/parks?parkCode=yell. Response for preflight has invalid HTTP status code 401
- jcarapia