这是一个简单的问题,我无法找到答案。
在 Node.js 中,当我形成 PATCH 请求时,我想将 if-match header 设置为 *。我就是这样做的吗?这行得通吗?
headers: {
'if-match': '*'
}
最佳答案
是的,它有效。
这是一个简单的例子。
客户端Node.js程序:
const http = require('http');
const agent = new http.Agent();
let req = http.request({
agent: agent,
port: 3000,
path: '/',
method: 'PATCH',
headers: {
'if-match': '*'
}
});
req.end();
服务器 Node.js 程序(也可以是其他服务器端技术):
const http = require('http');
let server = http.createServer(function(req, res) {
console.log(req.url);
console.log(req.method);
console.log(req.headers);
res.end();
});
server.listen(3000, function() { console.log("Server Listening on http://localhost:3000/"); });
控制台打印结果为:
/
PATCH
{ 'if-match': '*',
host: 'localhost:3000',
connection: 'close',
'content-length': '0' }
您可以看到服务器端同时收到了 PATCH
和 if-match
header 。
关于javascript - 带有 If-Match header 的 Node.js PATCH 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44598225/