// Importing https module
const http = require('http');
// Setting the configuration for
// the request
const options = {
hostname: 'jsonplaceholder.typicode.com',
path: '/posts',
method: 'GET'
};
// Sending the request
const req = http.request(options, (res) => {
let data = ''
res.on('data', (chunk) => {
data += chunk;
});
// Ending the response
res.on('end', () => {
console.log('Body:', JSON.parse(data))
});
}).on("error", (err) => {
console.log("Error: ", err)
}).end()
var options = {
host: 'www.google.com',
port: 80,
path: '/upload',
method: 'POST'
};
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write('data
');
req.write('data
');
req.end();
const https = require('node:https');
https.get('https://encrypted.google.com/', (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
}).on('error', (e) => {
console.error(e);
});