![](/img/trans.png)
[英]Learning JS - How do you retrieve a value from a key/value pair, when that pair is itself a value of another pair, all within an array?
[英]How to set a HTTP Header Key/Value Pair within the MEAN Stack
我正在使用MEAN堆棧,需要在我的Web應用程序中設置HTTP標頭鍵/值對。
即my_key: my_value
使用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中的CORS:[請參閱@mscdex答案]
將標題字段設置為值
res.set('Content-Type', 'text/plain');
或傳遞一個對象以一次設置多個字段。
res.set({
'Content-Type': 'text/plain',
'Content-Length': '456'
})
別名為
res.header(field, [value])
有關更多信息,請閱讀Express文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.