HttpErrorResponse when calling .net core method from Angular 8

techno

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: "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

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

            return Ok("success");
        }
sleimanov

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

The best way is to change the responseType:

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

This is the reference: https://angular.io/guide/http#requesting-non-json-data

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

calling .net core method from angular gives error: failed to load resource: the server responded with a status of 404 ()

From Dev

Issuer is Invalid when calling ASP.NET Core 2.2 from Angular 7 (MSAL)

From Dev

.Net Core API method not calling

From Dev

Connection ID when calling SignalR Core Hub method from Controller

From Dev

Calling my .NET Core Teams Bot from Angular

From Dev

How to pass multiple parameters from angular 8 to .NET Core API

From Dev

Get Image(Binary Data) from database with .Net Core and Angular 8

From Dev

How to wait for async method to finish when calling a external service in .net core?

From Dev

Error when calling method on web api controller - .Net Core 1.1 / EF 1.1

From Dev

Error 404 when calling POST method in asp.net mvc Core 2.1

From Dev

Angular HttpErrorResponse

From Dev

Angular 4 - Return HttpErrorResponse from interceptor

From Dev

Getting the error messages from HttpErrorResponse in an Angular application

From Dev

Calling C# method from JQuery Ajax in .NET Core Razor Pages

From Dev

POST method not working in .NET Core MVC while using Jquery , AJAX for calling api from View(html page)?

From Dev

Calling async action in asp.net core means file in formData is lost from c# API method

From Dev

502.3 when calling AcquireTokenAsync in .NET Core 2.2

From Dev

POST method calling from service Angular 6 to the REST using web api in asp.net mvc

From Dev

Getting 404 not found when calling Asp.Net Core MVC action from Jquery

From Dev

Bad Request error when calling from jquery ajax to API contrroller ASP.net Core

From Dev

Grpc.Core.RpcException when calling gRPC service from .NET MAUI app

From Dev

Angular 5: calling method from html

From Dev

Calling an angular component method from classic HTML

From Dev

Multiple times method calling from angular template

From Dev

Invalid JSON literal: xxx when calling ASMX service from Angular8

From Dev

NullPointerException when calling a Fragment method from Activity?

From Dev

NullPointerException when calling a method from a different class

From Java

NullPointerException when calling method from another class

From Dev

NullPointer Exception when calling a method from onResume

Related Related

  1. 1

    calling .net core method from angular gives error: failed to load resource: the server responded with a status of 404 ()

  2. 2

    Issuer is Invalid when calling ASP.NET Core 2.2 from Angular 7 (MSAL)

  3. 3

    .Net Core API method not calling

  4. 4

    Connection ID when calling SignalR Core Hub method from Controller

  5. 5

    Calling my .NET Core Teams Bot from Angular

  6. 6

    How to pass multiple parameters from angular 8 to .NET Core API

  7. 7

    Get Image(Binary Data) from database with .Net Core and Angular 8

  8. 8

    How to wait for async method to finish when calling a external service in .net core?

  9. 9

    Error when calling method on web api controller - .Net Core 1.1 / EF 1.1

  10. 10

    Error 404 when calling POST method in asp.net mvc Core 2.1

  11. 11

    Angular HttpErrorResponse

  12. 12

    Angular 4 - Return HttpErrorResponse from interceptor

  13. 13

    Getting the error messages from HttpErrorResponse in an Angular application

  14. 14

    Calling C# method from JQuery Ajax in .NET Core Razor Pages

  15. 15

    POST method not working in .NET Core MVC while using Jquery , AJAX for calling api from View(html page)?

  16. 16

    Calling async action in asp.net core means file in formData is lost from c# API method

  17. 17

    502.3 when calling AcquireTokenAsync in .NET Core 2.2

  18. 18

    POST method calling from service Angular 6 to the REST using web api in asp.net mvc

  19. 19

    Getting 404 not found when calling Asp.Net Core MVC action from Jquery

  20. 20

    Bad Request error when calling from jquery ajax to API contrroller ASP.net Core

  21. 21

    Grpc.Core.RpcException when calling gRPC service from .NET MAUI app

  22. 22

    Angular 5: calling method from html

  23. 23

    Calling an angular component method from classic HTML

  24. 24

    Multiple times method calling from angular template

  25. 25

    Invalid JSON literal: xxx when calling ASMX service from Angular8

  26. 26

    NullPointerException when calling a Fragment method from Activity?

  27. 27

    NullPointerException when calling a method from a different class

  28. 28

    NullPointerException when calling method from another class

  29. 29

    NullPointer Exception when calling a method from onResume

HotTag

Archive