[英]400 Bad Request in angular in Http Get request
When I try this URL: http://dummy.restapiexample.com/api/v1/employee/1 directly I get response:当我直接尝试这个 URL: http://dummy.restapiexample.com/api/v1/employee/1我得到响应:
But when I try to access this same URL from my angular application It is giving 400 Bad Request.但是,当我尝试从我的 angular 应用程序访问相同的 URL 时,它给出了 400 Bad Request。
In Service:服务中:
getEmpAPI = 'http://dummy.restapiexample.com/api/v1/employee'
getEmployee(id: string) {
return this.http.get(`${this.getEmpAPI}/${id}`)
}
In Component:在组件中:
onClick(evt: any, index) {
evt.preventDefault();
let id = index + 1;
this.empDataService.getEmployee(id).subscribe(
(emp) => {
console.log(emp);
}
)
} }
For reference this the API page all I have.作为参考,我所有的 API 页面。 http://dummy.restapiexample.com/ http://dummy.restapiexample.com/
Please help:请帮忙:
Are you sure there is a employee with the id of 0?您确定有一个 id 为 0 的员工吗? in the above example you are using 1在上面的示例中,您使用的是 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.