I'm trying to send a post request to a json file in typescript, Angular with HttpClient. However, I get a 404 not found error, saying it cannot fine the file results.json. I find this weird because the get requests all work perfectly fine. Currently I'm using Angular 15.
I tried the following:
let emptyObject = {};
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.http.post('/assets/results.json', emptyObject, {headers})
.subscribe((res:any) => {
console.log(res);
}, error => {
console.log(error)
});
The file results.json is empty and just looks like this:
[ ]
When executing the function it says:
HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: 'Not Found', url: 'http://localhost:4200/assets/results.json', ok: false, …}
I know the file exists and the filepath works because I use the same one for get requests. Is there maybe an option I need to enable or disable? It should be possible right?