1. 程式人生 > >node https post傳送資料

node https post傳送資料

let secCheck = await new Promise<string>((resolve, reject) => {

let postData = JSON.stringify({

content: p.content

})

let options ={

hostname:'api.weixin.qq.com',

path:'/wxa/msg_sec_check?access_token=' + access_token,

method:'POST',

headers:{

'Content-Type': 'application/json',

'Content-Length': Buffer.byteLength(postData)

}

}

let req = https.request(options, res => {

let dd = '';

res.on('data', secCheck => {

dd += secCheck;

});

res.on('end', secCheck => {

resolve(dd);

})

res.on('error', err => {

reject(err);

});

});

req.on('error', err => {

console.log(4,err)

reject(err);

})

//記得這兩句鴨!!!!!!!!!!!!!!!!!!!!!!!

req.write(postData);

req.end();

})