角度发布请求未显示任何响应数据

时间:2019-06-28 05:39:55

标签: angular django-rest-framework http-post postman response

当我与邮递员发送发帖请求时,我得到了预期的状态为400的响应 但是当我使用带有角度的http.post的浏览器发送请求时,我只有400错误而没有响应数据 here is my postman request with response

here is my browser request without response

这是我用角度发送的请求

signUp(data: {}) {
return this.http.post(this.baseUrl + '/blog/api/user/', data).pipe(
  map(resp => resp),
  catchError(err => {
    throw err;
  })
)}

在这里我console.log我的回应

    onSubmit() {
    if (!this.signupForm.valid) {
      return;
    }
    this.authService.signUp(this.signupForm.value)
    .subscribe(
      resp => console.log(resp),
      err => console.log(err)
    );
  }

1 个答案:

答案 0 :(得分:0)

尝试像这样删除服务中的管道,以查看其是否有效

signUp(data: {}) {
  return this.http.post(this.baseUrl + '/blog/api/user/', data).pipe(
    map(resp => resp),
    catchError(err => {
      throw err;
    })
)}

更改为此

signUp(data: {}) {
  return this.http.post(this.baseUrl + '/blog/api/user/', data);
}

通常我们在组件中使用运算符来修改来自API的数据

在您的组件中这样做

this.authService.signUp(this.signupForm.value)
   .pipe(
        map(resp => resp),
        catchError(err => {
          throw err;
        })
    )
    .subscribe(
      resp => console.log(resp),
      err => console.log(err)
    );
相关问题