无法通过将电子邮件作为angular中的参数传递来获得API响应

我无法通过调用Rest API的post方法获得响应,我也尝试过邮递员获得响应。

我尝试了以下代码: data.service.ts

getcategories(){

    request.setattribute("uid",user == null? "anon" : user.id)

通过调用api将其清空

heishashengzhe111 回答:无法通过将电子邮件作为angular中的参数传递来获得API响应

尝试这种方式

this.http.post(this.baseUrl+'/courses/get_all_courses/',{},{params:params1},options);

如果您要发送带有空正文的http帖子,请发送http.post(url: string,body: any,options:{// options here})

,

嗨,我有解决方案:服务文件:

getCourse(data:any){

let headers = new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'});
  return this.http.post(this.baseUrl+'/courses/get_all_courses/',data,{headers,responseType: 'json',observe: 'response'});

}

.ts文件:

    const params = {
      email: "info@evidyahub.com"
    }

    this.data.getCourse(params).subscribe(
      (res: any) => {
        if (!res) return;
        let aa = JSON.stringify(res.body.data);//console.log(aa);
        let getCourses = JSON.parse(aa);
        //console.log(getCourses);
        this.courses = getCourses
      },error => {
        console.log("Error in API",error)
      }
    )
本文链接:https://www.f2er.com/3140228.html

大家都在问