Not posting body data
See original GitHub issueI am trying send a post request but the json data in body attribute is not getting sent. I tried sending this request with Postman and it is working just fine.
Code:
const fetch = require('node-fetch')
fetch('https://test.instamojo.com/api/1.1/payment-requests/', {
method: "POST",
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Api-Key': 'xxx',
'X-Auth-Token': 'xxx'
},
body: JSON.stringify({
purpose: 'FIFA 16',
amount: '2500'
})
}).then(res => res.json())
.then(data => console.log(data)).catch(e => console.log(e))
Error:
{ success: false,
message:
{ amount: [ 'This field is required.' ],
purpose: [ 'This field is required.' ] } }
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
post request not working, claims body data is not present ...
I've fixed the problem. There's 2 ways of fixing this. Solution 1: Add headers. fetch('http://localhost:3000/api/content', { method: 'post', ...
Read more >Add a Request Body to a POST Request | API Connector
If it says invalid POST body data that means it isn't valid JSON. Maybe you've inadvertently copied in some extra characters, or maybe...
Read more >Http.request not sending POST data? (SOLVED) - Defold Forum
request fires because I receive an e-mail as expected, but the POST data (which I intend to be the body of the e-mail)...
Read more >POST - HTTP - MDN Web Docs
The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header....
Read more >How do I post request body with Curl? - ReqBin
What is HTTP body? The HTTP body is the data sent in an HTTP message to the other side during client-server communication. Not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
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
@hrwndr I think the body should be encoded as form parameters, not JSON when the Content-Type is
application/x-www-form-urlencoded
. I hope this will help. Post with form parametershave been one year without any respond.