【问题标题】:Http failure during parsing | 204 status with error state解析时Http失败 |带有错误状态的 204 状态
【发布时间】:2019-06-05 09:25:15
【问题描述】:

我试图在我的服务器上安装的 influxdb 中记录我的原生 Angular 应用程序日志。将日志发布到服务器 API 成功并返回 204 状态代码以及错误。 为此,我参考了许多答案,例如this,但对我不起作用。

错误:

{
JS:   "headers": {
JS:     "normalizedNames": {},
JS:     "lazyUpdate": null,
JS:     "headers": {}
JS:   },
JS:   "status": 204,
JS:   "statusText": "Unknown Error",
JS:   "url": null,
JS:   "ok": false,
JS:   "name": "HttpErrorResponse",
JS:   "message": "Http failure during parsing for (unknown url)",
JS:   "error": {}
JS: }

API 调用:

const req = `spl.hpft AppComponent="testing",Message=" ${error.message ? error.message : null}",Error="${error.toString()}"`;
 const headers = new HttpHeaders().set('Content-Transfer-Encoding', 'binary');
 console.log('influxdb request sent');
  this.httpClient.post(InfluxDb_Log, req, {headers:headers,responseType:'text' }).subscribe(payloadResponse => {
  console.log('payloadResponse', payloadResponse);
  console.log('influxdb response received', payloadResponse);
}, error => {
  console.log('influx error', error);
}); 

【问题讨论】:

  • InfluxDb_Log 的值是多少,通过邮递员工具进行 post call 时是否有效?
  • 是的,它通过邮递员工作
  • 显示/评论您在使用邮递员时收到的请求和响应
  • request : dbname.test AppComponent="testing",Message="这是测试错误",Error="错误:这是测试错误"

标签: angular typescript httpclient nativescript http-status-code-204


【解决方案1】:

我认为您的其余 api 返回 content-type="application/json".nativescript xhr 检查 content-type 响应标头。如果 content-type ="application/json" 那么它将解析数据。实际上返回 204空字符串,所以它会抛出错误。我认为这个应该是修复本机脚本团队。所以你可以通过从响应中删除 content-type 标头或传递 content-type = "text" 来修复它,两者都将支持原生脚本。试试吧

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 2016-03-22
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2019-12-15
    相关资源
    最近更新 更多