10

I'm using request in my app to send a POST request over HTTPS with Client Authentication. Request always throws an error Error: Invalid URI "/" and I couldn't do anything to solve it. I've tried used url.parse instead of passing a string but it's still the same.

request.post({
        uri: 'https://localhost:5000',
        key: credentials.key,
        ca: credentials.ca,
        cert: credentials.cert,
        passphrase: credentials.passphrase,
        rejectUnauthorized: false
    }, { form: { data: payload }});
mscdex
  • 104,356
  • 15
  • 192
  • 153
Nick Shvelidze
  • 1,564
  • 1
  • 14
  • 28

1 Answers1

12

Turns out it was caused by passing the second object to request.post, it should be inside the first object.

request.post('https://localhost:5000/', {
    key: credentials.key,
    ca: credentials.ca,
    cert: credentials.cert,
    passphrase: credentials.passphrase,
    rejectUnauthorized: false,
    form: { data: payload }
});
Nick Shvelidze
  • 1,564
  • 1
  • 14
  • 28
  • Thank you. In my case, the issue was `request(options, {}`. Empty options. Your answer helped me spot my error. – Drazisil Mar 01 '18 at 02:53