文章内容

2019/9/4 15:49:51,作 者: 黄兵

Angular HttpClient post 提交方式

最近由于前后端提交方式不一样,导致一直报错,之后对比了一下,后端使用POST接收数据,前端使用GET提交数据,牛头不对马嘴。

修改前端提交方式,在Angular中HttpClient post提交方式如下:

getUserIdByEmail(UserId: string): Observable {
    const body: string = JSON.stringify(UserId);
    return this.http.post('/api/identity/GetEmail', body, {
      headers: new HttpHeaders().set('Content-Type', 'application/json'),
    }).pipe(
      map((response: Response) => {
        return response;
      }),
      catchError((error: any) => {
        return throwError(error);
      }));
  }

其中UserId是要提交的参数。

后端具体API接口查看地址:OAuth API


黄兵个人博客原创。

转载请注明出处:黄兵个人博客 - Angular HttpClient post 提交方式

分享到:

发表评论

评论列表