json body not posted
See original GitHub issueHi. I’m trying to make a post request with json in the body included. The request is indeed a post request but the json data isn’t posted.
Here is an example:
fetch("http://127.0.0.1:8080/v1.0/users", {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'foo',
pass: 'bar'
})
}).then(response => console.log(response))
Results in the following request headers:
POST /v1.0/users HTTP/1.1 Host: 127.0.0.1:8080 Connection: keep-alive Content-Length: 28 accept: application/json Origin: http://127.0.0.1:3000 User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36 content-type: application/json DNT: 1 Referer: http://127.0.0.1:3000/registration Accept-Encoding: gzip, deflate Accept-Language: nl,en-US;q=0.8,en;q=0.6
There is no data posted. Can anyone point me in the right direction? Thanks!
Issue Analytics
- State:
- Created 8 years ago
- Reactions:20
- Comments:48 (3 by maintainers)
Top Results From Across the Web
Why simple json request body in Postman is not working
The POST URL you are using might be wrongly written. 400 typically means you passed something invalid to the API.
Read more >JSON POST request using app sends empty body · Issue #8455
Endpoint receives request with right Content-Length and -Type but the Body is empty. Changing to Raw Text in Postman with the same bod......
Read more >Making a JSON POST Request With HttpURLConnection
A quick and practical introduction to issuing POST requests using HttpURLConnection.
Read more >Add a Request Body to a POST Request | API Connector
If your POST request isn't working, a likely cause is a mismatched content type. Try adding in a content type into the header...
Read more >How to receive JSON POST with PHP ? - GeeksforGeeks
In this article, we will see how to retrieve the JSON POST with PHP, ... stream that allows us to read raw data...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@npassaro ok, I got it - the following works. Followed the example on MDN:
I have the exact same problem, did anyone know a fix for this?
From what I’ve observed, the problem seems to come from the
Content-Type
header not being set.On the console I only only see:
["text/plain;charset=UTF-8"]