为什么在某些路径上不支持某些HTTP方法,如PUT和POST?

时间:2017-12-11 16:08:18

标签: node.js http express server

为什么此代码会响应请求,而不支持以下代码?

---------------------------支持这些----------------- --------

app.put('/dishes/:dishId', (req, res, next) => {
  res.write('Updating the dish: ' + req.params.dishId + '\n');
  res.end('Will update the dish: ' + req.body.name + 
        ' with details: ' + req.body.description);
});


app.post('/dishes', (req, res, next) => {
 res.end('Will add the dish: ' + req.body.name + ' with details: ' + req.body.description);
});

---------------------------不支持这些---------------- --------

 app.put('/dishes', (req, res, next) => {
  res.statusCode = 403;
  res.end('PUT operation not supported on /dishes');
});

 app.post('/dishes/:dishId', (req, res, next) => {
  res.statusCode = 403;
  res.end('POST operation not supported on /dishes/'+ req.params.dishId);
});

0 个答案:

没有答案