LoginSignup
0
2

More than 3 years have passed since last update.

ReactでHTTPボディを送る方法

Posted at

やりたいこと

reactから req.body.id をnodeへ送って、nodeで、 req.body.id を受け取りたかった。その後、 req.body.id の値を使ってmongoから値を取得する流れ

react

    const fetchData = async () => {
      var params = new URLSearchParams()
      params.append('id', pass)
      const result = await axios.post('http://localhost:3000/signin', params);

node

  app.post('/signin', function(req, res) {
    User.findOne({_id: req.body.id}, function(err,obj) { 
        console.log(obj);

参考

axiosの使い方まとめ (GET/POST/例外処理)
[Web] HTTPリクエストの中身を学んでみた。GETやPOSTの違いなど

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2