I have a problem with symptoms similar to this question and several others, although the answers did not help me. I am trying to send a password using a simple HTML form to a Node application, but the request body continues to return.
Server:
app.use(bodyParser.urlencoded({extended: true}));
router.post('/login', (req, res) => {
console.log(req.body);
console.log(req.headers['content-type']);
});
the form:
<form action="/login" method="post">
<input type="password" id="password">
<button type="submit">Log In</button>
</form>
If I submit the form, I get the following:
{}
'application/x-www-form-urlencoded'
However, if I try to twist the endpoint, I get a non-empty req.body:
$ curl -X POST localhost:5000/login -d 'password=testpw'
{ password: 'testpw' }
'application/x-www-form-urlencoded'
What am I doing wrong?
source
share