[英]Cannot download node-sqlite3@4.2.0 - node-pre-gyp ERROR Tried to download(403) Access Denied - node.js
[英]403 access denied error with Node.js fetch on external API
我已经在 Heroku 上部署了我的 Node.js Koa API 应用程序。 我正在调用 USAJOB.gov API,它在我的本地主机上工作。 但是,在 Heroku 上,我收到此错误:
You don't have permission to access "http://data.usajobs.gov/$(SERVE_403)/api/search?" on this server.
这是我的 Koa 路由器片段:
router.get('/jobs', async (ctx) => {
const { keyword, location } = ctx.query;
const url = `https://data.usajobs.gov/api/search?
Keyword=${keyword}&LocationName=${location}`;
const host = 'data.usajobs.gov';
const userAgent = '<redacted>';
const authKey = '<redacted>';
const headers = {
Host: host,
'User-Agent': userAgent,
'Authorization-Key': authKey,
};
await fetch(url, {
headers,
method: 'GET',
});
}
因此,问题是是否应该使用凭据进行跨站点访问控制请求。 我无法弄清楚如何使用 node-fetch 配置它,但是一旦我阅读了解决方案(下面的链接),切换到 axios,配置了withCredentials: true
,并添加了headers: { 'X-Requested-With': 'XMLHttpRequest' }
,然后一切正常。
来源: axios删除方法给出403
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.