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 错误,如下图所示:

enter image description here

enter image description here

解决方法

看起来您没有随服务发送 api/profile/...,因为您的代理将 api 路由反向到后端服务器。