首页 > 解决方案 > 得到错误 OK 作为来自 http 帖子的响应

问题描述

我正在对节点服务器进行 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)
})

更新

错误图像

标签: angularangular-httpclient

解决方案


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


推荐阅读