繁体   English   中英

节点获取“api 密钥不是合法的 HTTP 标头”错误

[英]node-fetch "api key is not a legal HTTP header" error

我正在尝试使用 node-fetch 向外部 API 发出 GET 请求。 当我运行代码时,出现以下错误:

UnhandledPromiseRejectionWarning: TypeError: Bearer [api key]​ is not a legal HTTP header value

Bearer 密钥采用 JWT 格式,位于外部配置文件中以保护隐私。

这是我的代码:

let api_config = require('./api_config.json');
const fetch = require("node-fetch");

fetch(api_config.API_Domain + api_config.SUBJECTCODES_OPTIONS_URI, {
    method: 'GET',
    headers: { 
        'Authorization': "Bearer " + api_config.API_Key,
        "Content-type": "application/json",
        "Accept": "application/json", 
    }
}).then(res => res.json())
.then(json => console.log(json))

我有 sam 问题和同样的错误 nextjs ,我用encodeURI(url_list[url])替换url_list[url]如下

 return NextResponse.redirect(
            encodeURI(url_list[url]),
            301
        )

编码网址解决了我的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM