Angular-Ionic HttpClient Post request to Api retruns 400 but swagger returns 200/401


I have a Ionic App and a Api.

To authorize I send the Login Credentials in a Post request.

Swagger returns this:
correct login 200 response

wrong login 401 response

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'https://localhost:7206/auth/login', credentials, this.httpOptions)

I get a 400 Error

Chrome Network Post

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.


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).

Answered By – Fabian Strathaus

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published