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