我们使用$ http.post向我们的服务器发送请求,当服务器没有及时回复(大约3秒)时,我们的angularjs客户端发送另一个http.post。我们用tcpdump跟踪了这个,我们看到了2个不同的$ http.post。
这是我们的控制器:
var request = Local.testPost();
request.then(function successCallback(response) {
console.log(response);
}, function errorCallback(error) {
console.log(error);
});
这是我们的本地服务帖子:
this.testPost = function(){
var data = 'token='+User.getToken();
var request = $http(
{
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
url: self.server+'/api/cmd',
data: data
}
);
return request;
};
我们的服务器也记录了2个不同的帖子......
怎么可能? 谢谢大家!
更新:Tcpdump日志
16:53:38.058379 IP 192.168.1.66.52515 > 8.ip-xxxxxx.eu.http: Flags [P.], seq 581:1162, ack 355, win 4106, options [nop,nop,TS val 206302095 ecr 194158267], length 581: HTTP: POST /api/cmd HTTP/1.1
16:53:41.843608 IP 192.168.1.66.52515 > 8.ip-xxxxx.eu.http: Flags [.], ack 709, win 4095, options [nop,nop,TS val 206305864 ecr 194161726], length 0
16:53:41.848302 IP 192.168.1.66.52515 > 8.ip-xxxxx.eu.http: Flags [F.], seq 1162, ack 709, win 4096, options [nop,nop,TS val 206305868 ecr 194161726], length 0
16:53:41.848918 IP 192.168.1.66.52522 > 8.ip-xxxxxx.eu.http: Flags [S], seq 4161058194, win 65535, options [mss 1460,nop,wscale 5,nop,nop,TS val 206305868 ecr 0,sackOK,eol], length 0
16:53:41.884020 IP 192.168.1.66.52522 > 8.ip-xxxxxxx.eu.http: Flags [.], ack 3569763921, win 4117, options [nop,nop,TS val 206305903 ecr 194161768], length 0
16:53:41.884246 IP 192.168.1.66.52522 > 8.ip-xxxxxx.eu.http: Flags [P.], seq 0:581, ack 1, win 4117, options [nop,nop,TS val 206305903 ecr 194161768], length 581: HTTP: POST /api/cmd HTTP/1.1
16:53:41.884701 IP 192.168.1.66.52515 > 8.ip-xxxxxx.eu.http: Flags [.], ack 710, win 4096, options [nop,nop,TS val 206305903 ecr 194161768], length 0
16:53:45.629884 IP 192.168.1.66.52522 > 8.ip-xxxxxx.eu.http: Flags [.], ack 355, win 4106, options [nop,nop,TS val 206309616 ecr 194162704], length 0
16:53:54.452688 IP 192.168.1.66.52435 > 8.ip-xxxxxx.eu.http: Flags [.], ack 5234, win 4096, options [nop,nop,TS val 206318403 ecr 194164846], length 0
16:53:54.452696 IP 192.168.1.66.52435 > 8.ip-xxxxxx.eu.http: Flags [.], ack 5234, win 4096, options [nop,nop,TS val 206318403 ecr 194164846], length 0
16:53:54.452719 IP 192.168.1.66.52435 > 8.ip-xxxxxx.eu.http: Flags [F.], seq 1261, ack 5234, win 4096, options [nop,nop,TS val 206318403 ecr 194164846], length 0
答案 0 :(得分:1)
一个可能的原因可能是您的服务器响应408
状态,在这种情况下,某些重试会自动运行。如果408
不是“真实”408
,则不应回复//Function to change case
function upperCaseValue(element) {
//Test that passed element has a "value" field
if( typeof element.value !== void 0) {
//Overwrite value
element.value = element.value.toUpperCase();
}
}
//Fetch elements to watch
var search = document.getElementById("search");
var output = document.getElementById("output");
//Bind events
search.addEventListener("keyup", function(){
//Change case
upperCaseValue(search);
//Use input
output.innerHTML = search.value;
});
search.addEventListener("change", function(){
//Change case
upperCaseValue(search);
//Use input
output.innerHTML = search.value;
});
。
看看这个: https://github.com/angular/angular.js/issues/4806
欢呼声