2023-02-26 01:30
This commit is contained in:
33
getting-started/12_https_request_post.js
Normal file
33
getting-started/12_https_request_post.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const https = require('https');
|
||||
const body = JSON.stringify({
|
||||
id: 1234,
|
||||
message: 'Hello'
|
||||
});
|
||||
const options = {
|
||||
hostname: 'www.elex-project.com',
|
||||
port: 443,
|
||||
path: '/',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'User-Agent': 'Elex Node',
|
||||
'Content-Type': `application/json`,
|
||||
'Content-Length': body.length
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
const request = https.request(options, (response) => {
|
||||
console.log(`httpStatus: ${response.statusCode}`);
|
||||
|
||||
response.on('data', (data) => {
|
||||
process.stdout.write(data);
|
||||
});
|
||||
});
|
||||
|
||||
request.on('error', (error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
request.write(body);
|
||||
request.end();
|
||||
Reference in New Issue
Block a user