node.js - NodeJS_RequestLib - How do I set customHeaders?
问题描述
I'm using the request lib request in my project and I need to inform to the API of another company (I can't modify the server) that a transaction was did.
Anyway, to inform to this API I need to use a custom header named api_key
and when I try to do this, like that:
reqOptions = {
url: 'https://my_url_here.com',
body: JSON.stringify(transaction),
headers: {
'Content-Type': 'text/xml',
'charset': 'UTF-8',
'api_key:': 'my_api_key_here'
}
};
I'm getting the error:
error: TypeError [ERR_INVALID_HTTP_TOKEN]: Header name must be a valid HTTP token ["api_key:"]
How can I set the custom header?
解决方案
Try change:
'api_key:': 'ak_live_a2a8ffae58614a42f6ab67c80a552eb1488e6'
to:
'api_key': 'ak_live_a2a8ffae58614a42f6ab67c80a552eb1488e6'
推荐阅读
- r - 使用 Michaelis-Menten 曲线,我如何计算每个品种的临界值,以及如何测试它们是否存在显着差异?
- php - 如何让这个会话进入另一个 .php?edit id;?>
- javascript - 在一次数组迭代中按名称从数组中获取对象
- mysql - 两个虚拟列的数量差异
- javascript - onClick事件返回promise,需要在onclick中解析promise后调用一个函数
- python - 为什么我的函数声称这些线相交?
- java - 电话身份验证验证无法验证并引发此错误
- javascript - 触摸事件侦听器在 iframe 中不起作用
- c# - 是否有定义 HTML 解码语言的特定方法?
- linux - 如何为Android构建【openSSL-1.0.2u】,如果可能,如何合并Android Makefile?