Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
428 views
Welcome To Ask or Share your Answers For Others

1 Answer

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));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...