2

Im using NodeJS Request - Simplified HTTP Client

I seem to have problem working with HTTPS website, I am not getting result.

var request = require('request'); request.post({ url: "",//your url headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, form: { myfield: "myfieldvalue" } },function (response, err, body){ console.log('Body:',JSON.parse(body)); }.bind(this)); 

Tested the API endpoint(which I cant share) on Postman, I just turn off SSL and it works, how do I do the same with request plugin?

6
  • What's the error... Commented Oct 27, 2017 at 6:42
  • Why loopbackjs tag? Commented Oct 27, 2017 at 6:44
  • There is not clearly shaped question and description, which is very important for the stackoverflow and the users which will check after for similar questions. Commented Oct 27, 2017 at 6:45
  • I think this one relates to origin when do server-call-server. Commented Oct 27, 2017 at 6:47
  • @vsenko I am using loopback with this one. Commented Oct 27, 2017 at 6:48

1 Answer 1

9

Just add this lines:

 rejectUnauthorized: false,//add when working with https sites requestCert: false,//add when working with https sites agent: false,//add when working with https sites 

So your code would look like this:

var request = require('request'); request.post({ url: "",//your url headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, rejectUnauthorized: false,//add when working with https sites requestCert: false,//add when working with https sites agent: false,//add when working with https sites form: { myfield: "myfieldvalue" } },function (response, err, body){ console.log('Body:',JSON.parse(body)); }.bind(this)); 
Sign up to request clarification or add additional context in comments.

4 Comments

Could you please clarify what effect your suggested settings will cause? Options rejectUnauthorized and requestCert are not mentioned in the docs.
@vsenko, essentially it just disable the ssl verification. which is a bit unsafe, if you dont trust the service you are connecting to.
It seems to me that it would be a good idea to clarify this in the answer, so that no one would ever use this approach in production.
@MarkRyanOrosa which one actually disables ssl verification? rejectUnauthorized? requestCert? agent? And what do the other two do?