Y
Y
YasyaK2018-07-07 12:04:00
Web servers
YasyaK, 2018-07-07 12:04:00

Why isn't the POST (fetch) body coming?

Customer:

fetch('/chat', {
        method: 'POST',
        body: `INSERT INTO messages (textMessage, timeMessage, userName) VALUES ('hi', '2500-01-01' , 'Yana')`
    })

Server:
router.post('/',function(req,res,next){
  console.log('post!!!', req.body);
});

Server response:
post!!! {}

What's my mistake? Why doesn't the bodysuit come?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
YasyaK, 2018-07-07
@YasyaK

Problem solved like this.
Customer:

fetch('/chat', {
        headers: {body: `INSERT INTO messages (textMessage, timeMessage, userName) VALUES ('hi', '2500-01-01' , 'Yana')`},
        method: 'POST',
    })

Server:
router.post('/',function(req,res,next){
  console.log('post!!!', req.headers.body);
});

Is this the right decision? Can't figure out why this works and the previous one doesn't.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question