[英]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.