我无法通过调用Rest API的post方法获得响应,我也尝试过邮递员获得响应。
我尝试了以下代码: data.service.ts
getcategories(){
request.setattribute("uid",user == null? "anon" : user.id)
通过调用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)
}
)