是否可以在 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/