我有这个标题:
var header = {
'accept': 'application/json',
'x-application-id':applicationId,
'hashing': this.hashGenerator(location),
'content-type': 'application/json'
}
我也有这样的情况:
if(this.props.token != null){
header.access-token=this.props.token
}
但是我好像不能这样添加参数
header.access-token
有解决这个问题的想法吗? 预先感谢。
最佳答案
尝试:res.headers['access-token'] = this.props.token
此外,对于自定义 header ,您可能需要添加“x-”前缀
参见 https://www.w3schools.com/js/js_object_properties.asp有关 JS 中对象属性的更多信息
关于javascript - 如何向 header 请求添加参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50711928/