我的客户端正在发送1个POST请求,但是由于某种原因,我的服务器每2分钟重复处理一次。为什么这样做呢?
[当我运行代码并从客户端单击提交按钮时,客户端控制台将输出一次:
6/1/2018 @ 13:8:29 sendsettings request sent"
但是服务器控制台将输出:
6/01/2018 @ 13:08:29 sendsettings request received
6/01/2018 @ 13:08:29: ---INTRUDER ALERT---
6/01/2018 @ 13:10:29 sendsettings request received
6/01/2018 @ 13:10:29: ---INTRUDER ALERT---
6/01/2018 @ 13:12:29 sendsettings request received
6/01/2018 @ 13:12:29: ---INTRUDER ALERT---
6/01/2018 @ 13:14:29 sendsettings request received
6/01/2018 @ 13:14:29: ---INTRUDER ALERT---
等...
这是我的客户代码的简化版本:
<!DOCTYPE html>
<html>
<body>
<div id="inputs">
Password: <input type="password" id="password" name="password">
<input type="submit" id="submit" value="Submit">
</div>
<script>
document.getElementById("submit").onclick = submitInfoToServer;
var xhttpPost = new XMLHttpRequest();
function submitInfoToServer() {
xhttpPost.open("POST", "/sendSettings", true);
var password = document.getElementById("password").value
var sendString = JSON.stringify({
password: password
});
var currentdate = new Date();
var datetime = currentdate.getDate() + "/"
+ ((currentdate.getMonth()+1)) + "/"
+ (currentdate.getFullYear()) + " @ "
+ (currentdate.getHours()) + ":"
+ (currentdate.getMinutes()) + ":"
+ (currentdate.getSeconds());
console.log(datetime + ' sendsettings request sent')
xhttpPost.setRequestHeader("Content-Type", "application/json")
xhttpPost.send(sendString);
}
</script>
</body>
</html>
简化的服务器代码是:
var express = require('express')
var app = express()
var https = require('https')
var json = require('express-json')
var bodyParser = require('body-parser')
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.set('port', (process.env.PORT || 5000))
app.post('/sendSettings', function(request, response) {
var currentdate = new Date();
var datetime = currentdate.getDate() + "/"
+ pad((currentdate.getMonth()+1)) + "/"
+ pad(currentdate.getFullYear()) + " @ "
+ pad(currentdate.getHours()) + ":"
+ pad(currentdate.getMinutes()) + ":"
+ pad(currentdate.getSeconds());
console.log(datetime + ' sendsettings request received')
if(request.body.password == 'password')
console.log(datetime + ': correct password')
else
console.log(datetime + ': ---INTRUDER ALERT---')
})