I'm upgrading my Ionic app to version 4 and am running into a weird problem where I'm not sure the data is being properly submitted to my API.
I've stripped this down to about as basic as I can get it and the API still returns a 401 Unauthorized error.
I know the API works, because when I submit the same via Postman I receive the expected data...
I'm importing the HttpClient
...
import { HttpClient, HttpHeaders } from '@angular/common/http';
And here's my stripped down function, which runs when the submit button is clicked.
onSubmit() {
const headers = new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
});
let body = {
'username': 'test',
'password': 'test',
}
this.http
.post(this.apiService.url, body, { headers: headers })
.subscribe((data: any) => {
console.log(data);
}, error => {
console.log('error');
});
}
This all worked perfectly in Ionic 3, so I'm really confused as to why it's not working now.