Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty req.body with json parser #264

Closed
robertsLando opened this issue Sep 13, 2017 · 7 comments · May be fixed by clevyr/body-parser#4
Closed

Empty req.body with json parser #264

robertsLando opened this issue Sep 13, 2017 · 7 comments · May be fixed by clevyr/body-parser#4
Assignees
Labels

Comments

@robertsLando
Copy link

robertsLando commented Sep 13, 2017

After the update from version 1.0.0 to 1.18.1 req.body is empty.

Request:

var data = {email: email, password: pswd};
request = $.ajax({
            type: "POST",
            url: "/login",
            data: JSON.stringify(data),
            contentType: "application/json; charset=utf-8;",
            dataType: "json"
        });

Server side init:

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
@dougwilson
Copy link
Contributor

This module is currently version 1.18.1, very different from the version you mentioned. Is that just a typo?

@robertsLando
Copy link
Author

@dougwilson sorry I wrote 1.0.1 by error, I mean lastest version 1.18.1. If I install the last version the body is always empty. If I downgrade to 1.0.0 everything works.

@dougwilson
Copy link
Contributor

Downgrade what to 1.0.0, this module? The code you provided is working for me with your jQuery code in both 1.0.0 and 1.18.1

@dougwilson
Copy link
Contributor

Sorry, I made a typo when rewriting your jQuery. The issue is your content typs is invalid.

Instead of

application/json; charset=utf-8;

It needs to be

application/json; charset=utf-8

@dougwilson dougwilson self-assigned this Sep 13, 2017
@robertsLando
Copy link
Author

robertsLando commented Sep 13, 2017

@dougwilson I try to explain it better. I was using [email protected], I have upgrade it to 1.18.1 (the last version), after the upgrade I had empty body in req.body so I have downgrade body-parser back to 1.0.0 and things started working again. I still don't understand why it works with 1.0.0, was a bug in 1.0.0 version that made it work even with the ';' at the end of content type string or what else?

@dougwilson
Copy link
Contributor

That's correct, it was a bug that was fixed.

@robertsLando
Copy link
Author

Thanks @dougwilson. I have removed that ';' from all jquery requests in my project and now everyting works with lastest version 1.18.1.

@expressjs expressjs deleted a comment from abhiroopghatak Feb 10, 2019
@expressjs expressjs locked as resolved and limited conversation to collaborators Feb 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants