How to use req.body via get request in nodejs

后端 未结 2 830
孤独总比滥情好
孤独总比滥情好 2021-01-25 05:06

I have a form which uses a GET method. i also have an input with the name \'a\'. when i handle the request on the server side (nodejs) i want to be able to use req.body.a (in o

2条回答
  •  忘了有多久
    2021-01-25 05:25

    You can access req.body in GET method just as you would in a POST method. Here's an example:

    export const getFile = (req, res) => {
      const { fileId } = req.body; 
    
      console.log(fileId)
    }
    

    Although you CAN do this, I would suggest avoiding it because it goes against HTTP conventions. Instead, put whatever data you want in the URL parameters, which you can access in Node.JS using req.params.

提交回复
热议问题