繁体   English   中英

角度POST请求未执行

[英]Angular POST request not executed

我有一个似乎未执行的POST请求。

private loginBackend(): Observable<Response> {
const urlSearchParams = new URLSearchParams();
urlSearchParams.append('ticket', this.ticket.toString());
urlSearchParams.append('serviceURL', this.callbackURL);
this.loginEndPoint = (environment.backUri || window.location.origin) + environment.endpoints.login;
console.log("pass")
    return this.http
        .post(this.loginEndPoint, urlSearchParams, { withCredentials: true })
        .map((dt: any) => {
            this.isLoggedIn = true;
    this.isLogIn();
        })
        .catch(this.catchResponseError);
}

如果票证由后端验证,我试图将变量设置为true。

这是方法的调用:

 if (this.ticket) {
        // We try to autenticate
        return this.loginBackend()
 }

您需要使用订阅,否则它不会被调用

 if (this.ticket) {
        // We try to autenticate
        return this.loginBackend().subscribe(data=>
 }

当从Angular使用http客户端时,您会得到一个可观察到的回报。 这个可观察到的有来源。 就您而言,数据源是您的http调用。 仅当您订阅可观察对象时,才实际创建此源。

因此,基本上,您需要订阅您的Observable才能真正发出您的http发表请求:

 if (this.ticket) {
    // We try to authenticate
    return this.loginBackend().subscribe(data => {
        // Do your stuff with your response
    )
 }

希望能有所帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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