-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostTesting.js
More file actions
37 lines (36 loc) · 906 Bytes
/
postTesting.js
File metadata and controls
37 lines (36 loc) · 906 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
var http = require("http");
var fs = require("fs");
// This is an async file read
try {
fs.readFile(process.argv[4], "utf-8", function (err, data) {
if (err) {
console.log(err);
}
else if (data) {
// Set up the request
var post_req = http.request(
{
host: process.argv[2],
port: process.argv[3],
path: "/",
method: "POST",
headers: {
"Content-Type": "text/json",
"Content-Length": Buffer.byteLength(data),
},
},
function (res) {
res.setEncoding("utf8");
res.on("data", function (chunk) {
console.log("Response: " + chunk);
});
}
);
// post the data
post_req.write(data);
post_req.end();
}
});
} catch (error) {
console.log("Usage: postTesting <ip-address> <port> <json filepath>")
}