I have a Ionic App and a asp.net Api.
To authorize I send the Login Credentials in a Post request.
When sending my Post request like this:
httpOptions = {
headers: new HttpHeaders({ 'content-Type': 'application/json', 'accept': '*/*' })
};
login(credentials: {username: string; pw: string}): Observable <any>
{
return this.http.post('https://localhost:7206/auth/login', credentials, this.httpOptions)
}
I get a 400 Error
I don't know much about Http requests and all the answers I could find for http 400 errors is change the content type to aplication/json, which I already did.
Any Help/Tipps/Ideas are appreciated.
CodePudding user response:
Your API is, in the request body, expecting properties with the names name
and password
. But in your angular code it seems like you are sending the request body which only contains properties username
and pw
.
This is probably the reason why your server is sending a 400 error, which means you were sending a bad request (e.g. when your request body is not matching the expected schema).