Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在平均堆栈中设置HTTP头密钥/值对_Javascript_Angular_Express_Http Headers_Mean Stack - Fatal编程技术网

Javascript 如何在平均堆栈中设置HTTP头密钥/值对

Javascript 如何在平均堆栈中设置HTTP头密钥/值对,javascript,angular,express,http-headers,mean-stack,Javascript,Angular,Express,Http Headers,Mean Stack,我使用的是平均堆栈,需要在我的web应用程序中设置HTTP头密钥/值对 i、 e.my\u键:my\u值 使用Angular 5并找到以下代码: app.use('/api', function (req, res) { let url = config.API_HOST + req.ur req.headers['someHeader'] = 'someValue' req.pipe(request(url)).pipe(res) }) 但不确定如何应用于我的要求,因为

我使用的是平均堆栈,需要在我的web应用程序中设置HTTP头密钥/值对

i、 e.
my\u键:my\u值

使用Angular 5并找到以下代码:

app.use('/api', function (req, res) {
   let url = config.API_HOST + req.ur
    req.headers['someHeader'] = 'someValue'
    req.pipe(request(url)).pipe(res)
})
但不确定如何应用于我的要求,因为我认为我需要上述代码中的唯一一行是:

req.headers['my_key'] = 'my_value'

但不确定我是否需要
req.pipe
行。

在npm上至少使用一个中间件来处理Express中的COR:[请参阅@mscdex-answer]

将标题字段设置为值

res.set('Content-Type', 'text/plain');
或传递一个对象以同时设置多个字段

res.set({
  'Content-Type': 'text/plain',
  'Content-Length': '456'
})
化名为

res.header(field, [value])

有关更多信息,请阅读

在npm上使用至少一个中间件来处理Express中的COR:[请参阅@mscdex-answer]

将标题字段设置为值

res.set('Content-Type', 'text/plain');
或传递一个对象以同时设置多个字段

res.set({
  'Content-Type': 'text/plain',
  'Content-Length': '456'
})
化名为

res.header(field, [value])
有关更多信息,请阅读