尝试执行PUT方法时出现错误。错误是这样的:
PUT http://localhost:3000/Student/ 404 (Not Found)

这是来自stock.service.ts文件的摘录



updStudent(id: string, newName: string, newYear: string, newSemester: string, newScore: string): Observable<any>
    {
        console.log(JSON.stringify({
            name: newName,
            year: newYear,
            semester: newSemester,
            score: newScore
        }));
        return this.http.put("http://localhost:3000/Student/", +id,
        JSON.stringify({
                name: newName,
                year : newYear,
                semester : newSemester,
                score: newScore
            }));
     }





这是来自app.component.ts文件的摘录



selectedStudent: any;

updStudent(Id: string, newName: string, newYear: string, newSemester: string, newScore: string)
  {
    this.stockService.updStudent(this.selectedStudent.Id, newName, newYear, newSemester, newScore).subscribe(

      data =>
      {
        this.getAllStocks();
      }

    );
    console.log('here', Id , newName, newYear, newSemester, newScore);
  }





谁能帮我解决这个错误?请让我知道是否需要更多片段。谢谢。

Link full ts

最佳答案

被调用的Api不支持Put()调用。您应该使用Post Method调用

updStudent(id: string, newName: string, newYear: string, newSemester: string, newScore: string): Observable<any>
    {
        console.log(JSON.stringify({
            name: newName,
            year: newYear,
            semester: newSemester,
            score: newScore
        }));
        return this.http.post("http;//localhost:3000/Student/", +id,
        JSON.stringify({
                name: newName,
                year : newYear,
                semester : newSemester,
                score: newScore
            }));
     }

10-07 14:08