return result.res.data don't return the resp body outside of request func. am trying to wrap this in a function and be able to call it wth ext_id and domain_name as args and get the response body in return.
btw am new to js.
var urllib = require('urllib');
ext_id = 1;
domain_name = "map";
var api_cookie = "PHPSESSID=55700000;"
var api_bodyString = "action=checks_domaines&ext="+ ext_id +"&dom="+ domain_name;
headers = {
"Content-Length": api_bodyString.length
}
urllib.request('https://www.example.com:443/en/api/ch.php', {
method: 'POST',
headers: headers,
content: api_bodyString
}).then(function (result) {
if(result.res.statusCode == 200){
return result.res.data;
// console.log('status: %s, body size: %d, headers: %j', result.res.statusCode, result.data.length, result.res.headers);
// console.log('resp: %s', );
}}).catch(function (err) {
console.error(err);;
})
// it returns an error : result.res.data is not defined
//console.log(result.res.data)