I am working on a angular 6+ project that in some of its parts uses angular http services to make some api calls to the server and I try to convert these http services to the new httpClient service.
But I got strange error that I have not any idea on the error. The attempting part is below. Could you help me with it?
The working http example:
This example works fine and getting response properly
public userLogin(userData: LoginModel): Promise<any> {
let options = new RequestOptions({
headers: new Headers({
"Content-type": "application/json"
})
});
const model: LoginRequestModel = {
EncryptedUsername: this.helper.encrypt(userData.UserName),
EncryptedPassword: this.helper.encrypt(userData.Password),
Stamp: ""
}
let data = JSON.stringify(model);
return this.http.post(this.api + "login", data, options).toPromise();
}
The not working httpClient example:
I got an error on the console;
userLogin2(userData: LoginModel): Observable<any> {
let options = {
headers: new HttpHeaders({
"Content-type": "application/json"
})
};
const model: LoginRequestModel = {
EncryptedUsername: this.helper.encrypt(userData.UserName),
EncryptedPassword: this.helper.encrypt(userData.Password),
Stamp: ""
}
let data = JSON.stringify(model);
return this.httpClient.post<any>(this.api + "login", data, options);
}
and the error:
body: {error: "Collection 'v1' not found"}
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
status: 404
statusText: "Not Found"
url: "https://converting.azurewebsites.net/api/v1.0/login"