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: {}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM