forked from alibaba/anyproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsocket_sample.html
More file actions
56 lines (50 loc) · 1.37 KB
/
websocket_sample.html
File metadata and controls
56 lines (50 loc) · 1.37 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Anyproxy</title>
<link rel="icon" type="image/png" href="/favico.png" />
<style type="text/css">
.logPanel{
border: 1px solid #AAA;
}
.logPanel p{
padding-left: 20px;
margin: 10px;
white-space: nowrap;
}
</style>
</head>
<body>
<input type="text" id="J_data" placeholder="req id" value="1" / >
<button type="button" id="J_sendReq">Send</button>
<div class="logPanel" id="J_logPanel"></div>
<script src="./lib/anyproxy_wsUtil.js"></script>
<script type="text/javascript">
//print log
var logPanel = document.getElementById("J_logPanel");
function log(data){
var thisLog = "<p>" + new Date()+ "<br>" + data + "</p>";
logPanel.innerHTML = thisLog + logPanel.innerHTML;
}
//instantiate ws util
var ws = new anyproxy_wsUtil({
baseUrl : "127.0.0.1",
port : "8003",
onGetUpdate : function(content){
log("update id " + content.id + " , content :" + JSON.stringify(content));
},
onError : function(e){
console.log(e);
}
});
//to get some response body
document.getElementById("J_sendReq").addEventListener("click",function(e){
var id = document.getElementById("J_data").value;
log("request for body id=" + id + "...");
ws.reqBody(id,function(content){
log("body id " + content.id + " ,content :" + content.body);
});
});
</script>
</body>
</html>