question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello i’m using Fetch on Node with React and Browserify, i trigger this code from a form submit:

event.preventDefault();

var form = new FormData();
form.append('a', 1);

fetch('http://localhost:8080/login', {
      method: 'POST',
      body: form
})

Can’t figure out why the request sent to the server has empty body, no matter what i put in (i also tried strings as body).

Any ideas?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:17
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

36reactions
m-zavgorodniycommented, Oct 11, 2017

Thanks guys, saved me a day. Essentially, what did work out for me: Client: fetching with headers: { "Content-Type": "application/json" } Server: adding app.use(require("body-parser").json())

30reactions
madsilvercommented, Feb 5, 2017

I had the same problem. I solved using:

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it considered bad practice to perform HTTP POST without ...
Yes, it's OK to send a POST request without a body and instead use query string parameters. But be careful if your parameters...
Read more >
req.body is empty in POST requests : r/node - Reddit
Hi! I know this is basically a noob question but please bear with me. I noticed that POST requests on my node server...
Read more >
JSON POST request using app sends empty body · Issue #8455
1 Go to New Tab · 2 Set up POST call · 3 Click on Body · 4 Set type to Raw and...
Read more >
How to handle if JSON POST body is empty? - webMethods
Tell the client to send an empty JSON string, i.e. {} in the HTTP body when using Content-Type=application/json) · Tell the client to...
Read more >
Handling REST POST method with Empty body on MPGW in ...
While arguably an empty body in a POST is a valid REST concept, DataPower will reject an empty body if you have the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found