I am learning node, but can't figure out how to send a POST request with a string. Here is my code:
const h = require('https');
h.post("https://VLang.johnstev111.repl.co", "print('test')")
I am learning node, but can't figure out how to send a POST request with a string. Here is my code:
const h = require('https');
h.post("https://VLang.johnstev111.repl.co", "print('test')")
This should do pretty much what you wish, we log the response and any errors. I've set the content-type to 'text/plain', and you can change the data by setting the postData variable to whatever you wish.
const https = require('https');
// Put your post data here
const postData = "print(40 + 2)";
const options = {
hostname: 'VLang.johnstev111.repl.co',
method: 'POST',
headers: {
'Content-Length': postData.length
}
};
const req = https.request(options, (res) => {
console.log('Response: status:', res.statusCode);
console.log('Response: headers:', res.headers);
res.on('data', (d) => {
process.stdout.write("Response: " + d);
});
});
req.on('error', (e) => {
console.error("An error occurred:", e);
});
req.write(postData);
req.end();