Reputation: 9905
The server only accepts data sent in the headers.
Doing it using this code the server is getting empty object:
const request = require('request')
request.post({
url: 'https://.....',
body: { userid: 'cris', gameid: '12' },
headers: { "Content-Type": "application/x-www-form-urlencoded"}
})
Doing it with Postman, the server gets the correct data:
How can i use the code to send the data in the headers?
Edit:
A printscreen with server info displayed in the browser, should help.
Upvotes: 2
Views: 4673
Reputation: 2661
Try this
const request = require('request')
request.post({
url: 'https://.....',
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json, text/plain', 'userid':'cris', 'gameid':'12'}
})
Upvotes: 2
Reputation: 151
Try this
const request = require('request')
request.post({
url: 'https://.....',
body: JSON.stringify({ userid: 'cris', gameid: '12' }),
headers: { "Content-Type": "application/x-www-form-urlencoded"}
})
Upvotes: 0