且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTTPClient POST尝试解析非JSON响应

更新时间:2022-12-04 08:42:55

您已将responseType: 'text'放在httpOptions的错误部分中-它应位于headers外部中,像这样:

You've put responseType: 'text' in the wrong section of your httpOptions - It should sit outside of headers, like so:

private httpOptions = {
  headers: new HttpHeaders({
    'Accept': 'text/html, application/xhtml+xml, */*',
    'Content-Type': 'application/x-www-form-urlencoded'
  }),
  responseType: 'text'
};

使用以前的方法,将responseType的请求标头发送到服务器,而不是简单地向Angular发出指令以将响应实际视为文本.

With what you had before, a request header of responseType was being sent to the server, rather than simply having an instruction to Angular to actually treat the response as text.