I am developing a website with Angular 15 and I get the data from two APIs. One is public (The Movie Database) and I had no problem working with it.
I developed the other one and is deployed on my school server. I know my API works well because I tested it on several environments. I only have this problem on the website. I need to hide the url for privacy issues.
@Injectable({
providedIn: 'root',
})
export class LoginService {
constructor(private httpClient: HttpClient) {}
public login(userName: string, password: string): Observable<UserRemote> {
return this.httpClient
.get<UserRemote>(
'http://[...]/api/users/login?username=' + userName + '&password=' + password
)
.pipe(
map((response) => {
return response;
}),
catchError((error) => {
console.log('Error: ' + error.message);
return throwError(() => error.message);
}),
);
}
}
All I get when running it is "Unkown error":
The only difference I can tell from this url and one from The Movie Database is that it is http:// instead of https://. While working on an Android app, I had the same issue and I could fix it by adding allowcleartext=true, but I can't find the equivalent for Angular.
I tried using: this.sanitizer.bypassSecurityTrustResourceUrl('http://[...]/api/users/login?username=' + userName + '&password=' + password);. I'm not sure how it works, so it probably doesn't make sense here.