On an Angular 7 application I am calling a service:
this.messageService.send(model).pipe(
catchError(err => {
console.log('Error:', err);
return err;
}),
map((response: Response) => {
console.log(response);
})
);
The service method calls an API:
public send(model: Model): Observable<Response> {
const headers: HttpHeaders = new HttpHeaders();
headers.set('Content-Type', 'application/x-www-form-urlencoded');
console.log(model);
return this.httpClient.post<Response>>(`send`, model, { headers: headers });
}
I am able to see the model
on the Console when I do console.log(model);
But a breakpoint I have on the API does not fire and I don't get any error in catchError
.
The API action is ASP.NET Core 2.2. as follows:
[HttpPost("send")]
public async Task<IActionResult> Send([FromBody]Model model) {
return Ok();
}
NOTE:
On this same application I am able to use httpClient
with get
method without a problem.
Not sure what I am missing. Any idea?
UPDATE
I changed the Angular service code to:
public send(model: Model): Observable<Response>> {
const headers: HttpHeaders = new HttpHeaders();
headers.set('Content-Type', 'application/json');
console.log(model);
return this.httpClient.post<Response>>(`send`, JSON.stringify(model), { headers: headers });
}
Still not working.
This is an Angular problem as I just Posted JSon data with Postman.
It worked using Postman and without any kind authentication / authorisation.