NodeJS Request Post not working for HTTPS website

前端 未结 1 948
情书的邮戳
情书的邮戳 2020-12-21 10:18

Im using NodeJS Request - Simplified HTTP Client

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

var request = require(\'         


        
相关标签:
1条回答
  • 2020-12-21 10:43

    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));
    
    0 讨论(0)
提交回复
热议问题