从Angular 8调用.net核心方法时的HttpErrorResponse

编程入门 行业动态 更新时间:2024-10-07 14:22:00
本文介绍了从Angular 8调用核心方法时的HttpErrorResponse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在调用控制器方法并在操作完成后返回成功.但是我不断收到以下错误

I'm calling a controller method and returning success if the operation is complete.But i keep getting the following error

HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "localhost:5000/api/File/create", ok: false, …}headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}status: 200statusText: "OK"url: "localhost:5000/api/File/create"ok: falsename: "HttpErrorResponse"message: "Http failure during parsing for localhost:5000/api/File/create"error: {error: SyntaxError: Unexpected token s in JSON at position 0 at JSON.parse (<anonymous>) at XMLHtt…, text: "success"}__proto__: HttpResponseBase

[HttpPost("create")] public ActionResult<File> Create([FromBody]File file) { _fileService.Create(file); return Ok("success"); }

推荐答案

有一个未解决的问题,您有很多解决方案: github/angular/angular/issues/18396

There is an opened issue and you have many solutions: github/angular/angular/issues/18396

最好的方法是更改​​responseType:

The best way is to change the responseType:

this.http.get(url, {responseType: 'text'})

这是参考: angular.io/guide/http#requesting-non-json-data

更多推荐

从Angular 8调用.net核心方法时的HttpErrorResponse

本文发布于:2023-10-10 18:23:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479369.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:核心   方法   Angular   net   HttpErrorResponse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!