Encountering issues with HttpClient while trying to post data, I am faced with two distinct errors:
- When
booking
is treated as an object, the error message reads:
.Backend returned code 400, body was: [object Object]
- Converting
booking
to JSON format by usingJSON.stringify(booking)
triggers the error:
.Backend returned code 415, body was: null
What could be the reason for this?
public addBooking(booking): Observable<any[]> {
return this.http.post<any[]>(`${this.url}bookings`, booking)
.pipe(
catchError(this.handleError)
);
}
Object: Testing the following object structure in swagger yields successful results.
{
"firstDate": "2020-05-29",
"secondDate": "2020-05-29",
"productId": 0,
"userId": 0
}