-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-post.js
41 lines (33 loc) · 859 Bytes
/
test-post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const https = require('https');
const data = JSON.stringify({
message: 'Hello from test POST request',
timestamp: new Date().toISOString()
});
const options = {
hostname: 'test.dfanso.dev',
port: 443,
path: '/api/test',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(data)
},
rejectUnauthorized: false // Only for testing
};
const req = https.request(options, (res) => {
console.log('Status Code:', res.statusCode);
console.log('Headers:', res.headers);
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
console.log('Response:', responseData);
});
});
req.on('error', (error) => {
console.error('Error:', error);
});
req.write(data);
req.end();
console.log('Sending POST request with data:', data);