我目前使用 Node.js 和 express.js。对于我当前的项目,我需要访问 HTTP header 的原始字符串(字符集和已接受)。
express.js 中有一个函数返回那些字符集和接受的 header ,但是,这些是按质量排序的,因此在我需要的这种特殊情况下对我来说不可用。
req.accepted // Returns sorted array of accepted header
req.acceptedCharsets // Returns sorted array of accepted lang header
但是,我需要原始字符串 (iso-8859-5;q=.2, unicode-1-1;q=0.8, text/*;q=.5, application/json
).
现在有什么方法可以让我在我的 Express 应用中访问这些原始字符串吗?
最佳答案
请求头
如
var express = require('express');
var app = express.createServer();
app.get('/', function(req, res){
console.log(req.headers);
res.header('time', 12345);
res.send('Hello World');
});
app.listen(3000);
关于javascript - 如何使用 express.js 在 Node.js 中获取原始 HTTP header 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16517942/