Hello
This commit is contained in:
32
http/request-post.js
Normal file
32
http/request-post.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const https = require("https");
|
||||
const data = new TextEncoder().encode(
|
||||
JSON.stringify({
|
||||
todo: "Buy the milk 🍼",
|
||||
})
|
||||
);
|
||||
|
||||
const options = {
|
||||
hostname: "example.com",
|
||||
port: 443,
|
||||
path: "/todos",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Content-Length": data.length,
|
||||
},
|
||||
};
|
||||
|
||||
const req = https.request(options, (res) => {
|
||||
console.log(`statusCode: ${res.statusCode}`);
|
||||
|
||||
res.on("data", (d) => {
|
||||
process.stdout.write(d);
|
||||
});
|
||||
});
|
||||
|
||||
req.on("error", (error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
req.write(data);
|
||||
req.end();
|
||||
Reference in New Issue
Block a user