简体   繁体   中英

Why this post http request doesn't work in angular?

I'm trying to do this

login(username: string, password: string): Observable<User> { return this.http.post<User>('api/authenticate', { username, password }); }

but this doesn't work, also this code works

login(username: string, password: string): Observable<User> {
    return this.http.post<User>('www.google.com/api', { username, password });
}

i'm using angular 7, with proxy config

You have to call the login() function by subscribing the observable you return.

this.login.subscribe(response => {
    // Do your logic here
    // ...
})

Depending on your base URL setup your first request may just need relative path. '/api/authenticate' instead of 'api/authenticate'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM