Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法通过以参数形式传递电子邮件来获取API响应_Angular_Api_Http_Post_Service - Fatal编程技术网

Angular 无法通过以参数形式传递电子邮件来获取API响应

Angular 无法通过以参数形式传递电子邮件来获取API响应,angular,api,http,post,service,Angular,Api,Http,Post,Service,我无法通过调用RESTAPI post方法获得响应,我也尝试了postman获得响应 我尝试了以下代码: data.service.ts getcategories(){ 通过调用api将其设为null this.http.post(this.baseUrl+'/courses/get_all_courses/',{} ,{params:params1},options); 如果您发送的http post正文为空,请发送http.post(url:string,body:any,options

我无法通过调用RESTAPI post方法获得响应,我也尝试了postman获得响应

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

getcategories(){

通过调用api将其设为null

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

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

您好,我找到了解决方案:服务文件:

getCourse(数据:任意){

}

.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)
      }
    )

使用代理配置文件我已经使用了代理配置,但存在相同的问题?你能在问题中显示错误吗?网络选项卡响应我得到以下信息:{“params”:{“updates”:[{“param”:“email”,“value”:info@evidyahub.com“,“op”:“s”}],“cloneFrom”:{“更新”:null,“cloneFrom”:null,“编码器”:{},“映射”:null},“编码器”:{},“映射”:null}使用
home.componenet.ts;
不作为代码,而使用
getcategories(){
作为代码。很抱歉进行编辑。还应对其进行编辑
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'});
    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)
      }
    )