1

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Danny Ellis Jr.
  • 1,674
  • 2
  • 23
  • 38

1 Answers1

2

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.

str
  • 42,689
  • 17
  • 109
  • 127
  • how do you achieve that in request-promise? you are referring to request documentation. thanks – Gal Margalit Nov 12 '17 at 11:23
  • @GalMargalit ["Since request-promise wraps around request everything that works with request also works with request-promise."](https://www.npmjs.com/package/request-promise#cheat-sheet) So it shouldn't make a difference. – str Nov 12 '17 at 12:04
  • thanks, I'm meeting some difficulties. will give it a few more shots – Gal Margalit Nov 12 '17 at 12:45