2

我正在对节点服务器进行 api 调用。它是一个post call,但我收到错误作为响应,但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)
})

更新

错误图像

4

3 回答 3

5

我有同样的问题。我在后端使用 Spring REST API,它只是返回一个字符串,这是一个问题,因为 Angular HttpClient 需要 JSON。我通过将我的 String 包装在一个简单的 POJO 中并返回它来解决它。

于 2020-03-02T20:32:07.183 回答
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)
});
于 2019-11-17T06:48:01.997 回答
-2

我不确定,但可能是您的节点服务器代码写得不好,没有正确返回错误响应,您能否发布您的节点 API 代码,以便我们进行探索

于 2019-11-17T08:04:14.067 回答