从http帖子获得响应,得到正确的错误

问题描述 投票:0回答:1

我正在对节点服务器进行api调用。它是一个post调用,但是响应时出现错误,但是firebase上的数据更改了。

const header : HttpHeaders = new HttpHeaders()
header.append('Content-Type', 'application/x-www-form-urlencoded')

this.http.post('http://localhost:3000/s/getKey', { seqKey : 'invoices' }, {
  headers : header
}).subscribe(data => {
  console.log(data)
})
angular angular-httpclient
1个回答
0
投票

订阅后正确处理数据有助于您更好地查看响应数据。更好的方法是使用map()

this.http.post('http://localhost:3000/s/getKey', { seqKey : 'invoices' }, {
    headers : header
}).map(response => response.json())
.subscribe(data => {
    console.log(data)
}, error => {
  console.log(error)
});
© www.soinside.com 2019 - 2024. All rights reserved.