http - http post请求中的Angular2超时

标签 http post angular

是否可以在 post 请求中设置 3 秒超时?怎么样?

我现在的代码

this.http.post('myUrl', 
    MyData, {headers: Myheaders})
        .map(res => res.json())
        .subscribe(
            data => this.ret = data,
            error => console.debug('ERROR', error),
            () => console.log('END')
        );

最佳答案

您可以像这样使用 timeout 运算符:

this.http.post('myUrl', 
        MyData, {headers: Myheaders})
         .timeout(3000, new Error('timeout exceeded'))
         .map(res => res.json())
         .subscribe(
           data => this.ret = data,
           error => console.debug('ERROR', error),
           () => console.log('END')
         );

关于http - http post请求中的Angular2超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35779671/

相关文章:

iOS后台上传图片

http - 使用 HTTP + toPromise() 时如何在 Angular 2 中设置超时?

json - 了解 REST 响应和 HTTP 状态码

post - 调用 mandrill api 时连接拒绝 curl 错误

json - Angular 2 - 从 json 文件中获取数据

angular - 在组件之间共享 Auth Observable 值,无需多次执行

javascript - 单击项目时路由器无法路由

java - 应该如何通过 HTTP 公开 RSA 公钥?

php - cURL + HTTP_POST,不断收到 500 错误。不知道吗?

php $_POST 数组在表单提交时为空