request by POST

用POST送出請求

使用「axios」套件處理。(這裡使用版本為0.21.1)

const axios = require('axios')

axios
    .post(url, postData)
    .then(res => {
        clog(`statusCode: ${res.status}`)
        // console.log(res);
    
        if(res.status == 200){
            log("=>" + res.statusText);
        }
        else{
            log(`ERR=>${res.status} ${res.statusText} ${JSON.stringify(res.config)}`);
        }
    })
    .catch(error => {
        console.error(error)
    })

另外有使用NodeJS原生物件「 https」的方法,但較為複雜,想研究可以於參考位置查看。

參考:https://nodejs.dev/learn/make-an-http-post-request-using-nodejs

Last updated

Was this helpful?