当由于超时而没有来自服务器的响应时,我偶尔会遇到POST请求的重试.所有现代浏览器都具有幂等请求的重试逻辑(GET,HEAD等),但我无法推断为什么它会发生POST请求.
我正在使用一个带有3个路由和chrome浏览器的简单node.js服务器来测试这种情况.
/ : gives a html page with jquery and code snippets to fire ajax requests
/hi : gives a text response 'hello'
/sleep : request will timeout without any response
Run Code Online (Sandbox Code Playgroud)
默认情况下,node.js http服务器在2分钟后超时请求.
var http = require('http');
var server = http.createServer();
server.on('request', function(req, res) {
console.log(new Date() + ' ' + req.method + ' request on ' + req.url);
if (req.url === '/sleep') {
console.log('!!! sleeping');
} else if (req.url === '/') {
html = "$.post('/hi', {'for':'server'}, function() …
Run Code Online (Sandbox Code Playgroud)