-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp-client.js
44 lines (35 loc) · 987 Bytes
/
http-client.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
42
43
44
// import request from "request";
// import { createReadStream } from "fs";
// // const formData = {
// // firstName: "Matthias",
// // lastName: "Kohnen",
// // phone: "12312312312",
// // email: "[email protected]",
// // profilePic: createReadStream("./test.jpg"),
// // };
// // request.post(
// // { url: "http://localhost:8080/save", formData },
// // (err, response, body) => {
// // if (err) {
// // console.error(err);
// // } else {
// // console.log(body);
// // }
// // }
// // );
import { connect, constants } from "http2";
import { readFileSync } from "fs";
const client = connect("https://localhost:8080", {
ca: readFileSync("./localhost.cert"),
});
client.on("error", (err) => console.error(err));
const req = client.request({ [constants.HTTP2_HEADER_PATH]: "/" });
req.setEncoding("utf8");
let body = "";
req.on("data", (chunk) => {
body += chunk;
});
req.on("end", () => {
console.log(body);
});
req.end();