首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从角8调用.net核心方法时的.net

从角8调用.net核心方法时的.net
EN

Stack Overflow用户
提问于 2020-04-12 08:42:19
回答 2查看 979关注 0票数 1

我正在调用一个控制器方法,如果操作为complete.But,则返回成功,我继续得到以下错误

代码语言:javascript
复制
HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:5000/api/File/create", ok: false, …}headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}status: 200statusText: "OK"url: "http://localhost:5000/api/File/create"ok: falsename: "HttpErrorResponse"message: "Http failure during parsing for http://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

代码语言:javascript
复制
[HttpPost("create")]
        public ActionResult<File> Create([FromBody]File file)
        {
            _fileService.Create(file);

            return Ok("success");
        }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-12 10:20:00

有一个开放的问题,您有许多解决方案:https://github.com/angular/angular/issues/18396

最好的方法是更改responseType:

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

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

票数 2
EN

Stack Overflow用户

发布于 2020-04-12 10:04:00

角侧需要一个JSON,在您的示例中调用的action方法返回一个纯文本字符串。例如,以这种方式返回,客户端将获得一个JSON,并且它将能够解析它:

代码语言:javascript
复制
[HttpPost("create")]
public ActionResult<string> Create([FromBody]File file)
{
    _fileService.Create(file);
    return Ok(new { str="success" });
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61168850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档