如何解决GET http://localhost:4200/profile/1 404未找到
profile.service.ts
getProfile(userId:number): Observable<usermodel> {
return this.httpClient.get<usermodel>('/profile/inquireUserInfo/' + userId);
}
profile.component.ts
private getProfile() {
this.profileService.getProfile(this.userId).subscribe(data => {
this.usermodel = data;
},error => {
console.log(error);
});
}
proxy.config.json
{
"/api/*": {
"target": "http://localhost:8080","secure": false,"logLevel": "debug"
}
}
package.json
"scripts": {
"ng": "ng","start": "ng serve --proxy-config proxy.config.json","build": "ng build","test": "ng test","lint": "ng lint","e2e": "ng e2e"
}
但是,当我运行此应用程序时,出现 404 错误,如下图所示:
解决方法
看起来您没有随服务发送 api/profile/...
,因为您的代理将 api
路由反向到后端服务器。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。