Cristian Muscalu
Cristian Muscalu

Reputation: 9905

Nodejs send data in headers using request

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: enter image description here

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.

enter image description here

Upvotes: 2

Views: 4673

Answers (3)

Mustafa Mamun
Mustafa Mamun

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

chetan dev
chetan dev

Reputation: 621

try this

body: { "userid": "cris", "gameid": "12" }

Upvotes: 0

SabirAmeen
SabirAmeen

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

Related Questions