gpt4 book ai didi

node.js - 将自定义 header 添加到 'request'

转载 作者:搜寻专家 更新时间:2023-10-31 22:22:30 25 4
gpt4 key购买 nike

我正在通过我的快速配置中的以下设置来代理我的 api

  // Proxy api calls
app.use('/api', function (req, res) {
let url = config.API_HOST + req.url
req.pipe(request(url)).pipe(res)
})

config.API_HOST 在这里解析为我的 api url 和 req.url 是一些端点,即 /users 我尝试按照 npm 上的文档对于 request并像这样设置我的标题

  // Proxy api calls
app.use('/api', function (req, res) {
let options = {
url: config.API_HOST + req.url,
options: { 'mycustomheader': 'test' }
}
req.pipe(request(options)).pipe(res)
})

但我无法在网络下的 chrome 开发工具中看到我的自定义 header 。

最佳答案

是这样实现的

  app.use('/api', function (req, res) {
let url = config.API_HOST + req.ur
req.headers['someHeader'] = 'someValue'
req.pipe(request(url)).pipe(res)
})

关于node.js - 将自定义 header 添加到 'request',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38332492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com