nodejs的https请求

使用axios请求时,报错:`unable to verify the first certificate`

找了几个解决办法 发现都不行,就使用request进行请求,发现还是“unable to verify the first certificate”,

根据 https://www.reddit.com/r/node/comments/7vyc2q/cant_get_https_request_with_certificate_to_work/  给出的解决办法,

在请求头中加 strictSSL: false

请求的url需要加参数时,又报错:

Error: options.uri is a required argument

const url ='请求地址';
    request({
        method: 'GET',
        uri: url,
        strictSSL: false
    }, function (error, response, body) {
        if (!error && response.statusCode == 200) {
            let deleList = JSON.parse(body);            
        }
    })
//有参数时
    const leturl = '请求地址';
    request({
        method: 'GET',
        uri: leturl,
        qs: {
            offset: 0,
            limit: delegateTotal
        },
        strictSSL: false
    }, function (err, res, data) {
        if (!err && res.statusCode == 200) {
            let proList = JSON.parse(data);
        }
    })

//post有参数的请求,qs: {} 改为 form: {}

 

posted on 2020-12-24 16:55  长安乐眠  阅读(1388)  评论(0编辑  收藏  举报