最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why is req.body empty? - Stack Overflow

programmeradmin0浏览0评论

Server:

//Body Parser
var bodyParser = require("body-parser");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false}));

Client:

<form enctype="multipart/form-data" method="post" action="../users/editProfile" class="uploadForm">

For some reason, req.body is always empty when I submit the form. It was working perfectly fine before and to my knowledge the only thing I added where 9 more inputs for a total of 15.

What could have caused this ?

I already checked this: req.body empty on posts

None of the answers seem to solve my problem.

Server:

//Body Parser
var bodyParser = require("body-parser");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false}));

Client:

<form enctype="multipart/form-data" method="post" action="../users/editProfile" class="uploadForm">

For some reason, req.body is always empty when I submit the form. It was working perfectly fine before and to my knowledge the only thing I added where 9 more inputs for a total of 15.

What could have caused this ?

I already checked this: req.body empty on posts

None of the answers seem to solve my problem.

Share Improve this question edited Aug 25, 2017 at 16:44 abagshaw 6,6226 gold badges43 silver badges80 bronze badges asked Aug 25, 2017 at 16:29 TheProgrammerTheProgrammer 1,5094 gold badges30 silver badges54 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

You've loaded body parsers that can support:

  • URL encoding
  • JSON encoding

Your form is configured to use multipart/form-data, which is neither of those.

Use the multer parser for multipart/form-data bodies.

发布评论

评论列表(0)

  1. 暂无评论