Danny Ellis Jr.
Danny Ellis Jr.

Reputation: 1706

Request-Promise-Native ignores specified headers

I am somewhat new to Nodejs. I am working on a pair of Microservices, and I need one to post data to the other. I am using the request-promise-native library.

My code is to make the call is like this:

  const options = {
            method: 'POST',
            uri: url,
            formData: {
                command: command,
                version: version,
                session_id: sid,
                aicc_data: data
            },
            headers: {
                'content-type' : 'application/x-www-form-urlencoded'
            }
        }

         rp(options)

However, when I inspect the request as it come in to the other server, the header I have specified does not appear.

headers: { 'content-type': 'multipart/form-data; boundary=--------------------------395968157759002211606136',
  host: 'localhost:9000',
  'content-length': '513',
  connection: 'close' }

What am I doing wrong?

Upvotes: 1

Views: 615

Answers (1)

str
str

Reputation: 45009

options includes a formData object which enforces multipart/form-data.

You should add the form object instead when you want to use application/x-www-form-urlencoded.

Upvotes: 2

Related Questions