Created
June 20, 2018 08:18
-
-
Save neoshrew/f398f9644b092bc4c71f3b7831b44349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var resp_body = ''; | |
await new Promise((resolve, reject) => { | |
var request = https.request(post_options, res => { | |
res.on('data', chunk => {resp_body += chunk}); | |
res.on('error', err => { | |
console.log("Error in POST:", err); | |
reject(err); | |
}); | |
res.on('end', () => { | |
var msg = 'Got HTTP/' + String(res.statusCode) + ' : ' + resp_body; | |
console.log(msg); | |
if (res.statusCode != 200) { | |
reject(new Error(msg)); | |
} else { | |
resolve(); | |
} | |
}); | |
}); | |
request.on('error', err => { | |
console.log(err); | |
reject(err); | |
}); | |
request.write(''); | |
request.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment