-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.html
124 lines (111 loc) · 3.59 KB
/
post.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MemePI</title>
<link rel="stylesheet" type="text/css" href="shoelace.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="support.css">
</head>
<body>
<script type="text/javascript">
var http = require("http")
function post() {
frame = document.getElementById('iframe')
frame = frame.contentWindow || frame.contentDocument.document || frame.contentDocument;
frame.document.open()
var host = document.getElementById('host').value
var upath = document.getElementById('path').value
var uport = document.getElementById('port').value
var data = document.getElementById('data').value
console.log(host, upath, uport, data)
// if (uport === ""){ port = 80}
// if (upath === ""){ path = "/"}
// if (host === "") { host = "127.0.0.1"}
var options = {
hostname: host,
port: uport,
path: upath,
method: "POST",
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data)
}
}
const req = http.request(options, (res) => {
var {headers, statusCode} = res
var type = headers["content-type"]
res.setEncoding('utf8');
let heads = ""
let file = ""
res.on('data', (chunk) => {
file += chunk
});
res.on('end', () => {
for (key in headers){
let adding = `${key}: ${headers[key]}\n`
heads += adding
}
document.getElementById('headers').innerHTML = heads
document.getElementById('status').innerHTML = statusCode
file = type !== "text/html" ? "<style>@font-face {font-family: 'Inconsolata';src: url('./Inconsolata/Inconsolata-Regular.ttf');}body{font-family: 'Inconsolata';}</style>"+file : file
frame.document.write(file)
});
});
req.on('error', (e) => {
frame.document.write(`Problem with request: ${e.message}<br>`)
// throw e
});
// write data to request body
req.write(JSON.stringify(data));
req.end();
}
</script>
<div class="row">
<div class="col-10 offset-1">
<h1>Post <i class="fa fa-envelope"></i></h1>
<p>Send post requests and analyze the responses</p>
</div>
</div>
<div class="row">
<div class="col-10 offset-1">
<div class="input-field">
<label>Hostname</label>
<input type="text" id="host" value="localhost">
</div>
<div class="input-field">
<label>path</label>
<input type="text" id="path" value="/">
</div>
<div class="input-field">
<label>port</label>
<input type="text" id="port" value="8000">
</div>
</div>
</div>
<div class="row">
<div class="col-10 offset-1">
<textarea id="data">
{"data": "to post"}</textarea>
<br>
<button type="button" class="button-block" onclick="post()">Submit</button>
<br><hr>
</div>
</div>
<div class="row">
<div class="col-10 offset-1">
<h3>Headers</h3>
<pre id="headers"></pre>
<h5>Status</h5>
<pre id="status"></pre>
</div>
</div>
<div class="row">
<div class="col-10 offset-1">
<h3>Browser content</h3>
<div id="err"></div>
<iframe class="iframe" id="iframe" width="100%"></iframe>
</div>
</div>
</body>
</html>