首页 > 解决方案 > 响应状态代码为空

问题描述

我在 Angular 7 中实现了 post 方法。我想要 post 请求的状态代码。

我做了以下。

const sub = this.service.regEvent(this.pId, this.email)
      .subscribe(response => {
        console.log('response:', response);
        if(response.httpStatusCode === 200) {
        }
});

this.subscriptions.push(sub);

注册事件方法

public regEvent(pId, email): Observable<any> {
    return this.http.post<any>(`this.endpointUrl?eventId=${pId}&email=${email}`,"").pipe(
      catchError(this.handleError)
    );
  }

在这里console.log('response:', response); 我得到空值。

在浏览器中我检查了它。

在此处输入图像描述

在邮递员也。

在此处输入图像描述

任何帮助将不胜感激。

标签: angulartypescriptangular-httpclient

解决方案


您将需要观察响应,例如

this.http.post<any>(`this.endpointUrl?eventId=${pId}&email=${email}`,"",{observe: 'response'})

推荐阅读