嗨,我正在尝试在角度服务中的 POST 方法 url 中传递参数以构造一个 URL 以从 API 获取一些数据,但是当我在组件文件上调用它时,我得到了错误响应。
我在哪里做错了?
示例我需要通过这种类型的 url:- https://something/api/v1/map/GetdetailsById?ID=EF-345-RHDJI34-EHI3
在服务中我正在做:-
// Http Options
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
//POST API to show lists
getOTList(): Observable<any> {
const params = new HttpParams()
.set('ID', 'EF-345-RHDJI34-EHI3');
return this.http
.post<any>(`${environment.Url}` + `${APIs.getList}`,{params}, this.httpOptions)
.pipe(
retry(1),
catchError(this.handleError)
)
}
我正在做的组件中的Ang :
ngOnInit(){
this.getLists();
}
getLists(){
this.addService.getOTList().subscribe((response:any) => {
if (response.IsSuccess == true) {
console.log(response);
}
else {
console.log("something is wrong.") //<========== getting this message in console
}
});
}