为什么此帖子http请求不能按角度工作?

时间:2019-04-02 19:22:28

标签: angular

我正在尝试这样做

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

但这不起作用, 这段代码也可以

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

我使用的是angular 7,具有代理配置

2 个答案:

答案 0 :(得分:0)

您必须通过预订返回的观测值来调用login()函数。

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

答案 1 :(得分:0)

根据您的基本URL设置,您的第一个请求可能只需要相对路径。 '/ api / authenticate'而不是'api / authenticate'。