加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 以角度$http确定请求超时

发布时间:2020-12-17 08:09:28 所属栏目:安全 来源:网络整理
导读:我发送一个http请求使用角度如下。 $http({ url: url,params: params,method:'POST',headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },timeout: 60000 //60 seconds}).success(function(data,status,headers,config) { //d
我发送一个http请求使用角度如下。
$http({
    url: url,params: params,method:'POST',headers: {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },timeout: 60000    //60 seconds
}).success(function(data,status,headers,config) {
    //do something 
}).error(function(data,header,config) {
    if(timedout){  //determine occurrence of timeout.
        //invoke timeout handler
    } else  
        //handle other error
    }
});

如何确定超时?

我已经观察到在这种情况下接收到状态码“0”。检查状态== 0是否安全?

请注意,我不是要求HTTP请求超时(状态码408)。

我已经做了如下…
var startTime = new Date().getTime();
$http.post(...)
    .success(function(resp,config) {...})
    .error(function(resp,config) {
        var respTime = new Date().getTime() - startTime;
        if(respTime >= config.timeout){
            //time out handeling
        } else{
            //other error hanndling
        }
    });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读