-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
52 lines (36 loc) · 998 Bytes
/
test.js
File metadata and controls
52 lines (36 loc) · 998 Bytes
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
42
43
44
45
46
47
48
49
50
51
52
const http = require('http');
const {
createHash,
} = require('node:crypto');
const hash = createHash('sha256');
hash.update('testpsk');
// Function to send a POST request to the server
function sendPostRequest() {
const options = {
hostname: 'people.mirandola2.workers.dev', //or localhost
//port: 60911,
path: '/data?name=name%20surname',
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Just-A-PSK': hash.digest('hex'),
},
};
const req = http.request(options, (res) => {
let responseBody = '';
res.on('data', chunk => {
responseBody += chunk;
});
res.on('end', () => {
console.log('Response from server:', responseBody);
});
});
req.on('error', (error) => {
console.error('Request error:', error);
});
// Write data to request body
req.end();
}
// Send POST request after a short delay to ensure server is ready
setTimeout(sendPostRequest, 1000);
hash.end();