尝试执行 PUT 方法时出现错误。错误是这样的:
PUT http://localhost:3000/Student/404(未找到)
这是 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);
}
谁能帮我解决这个错误吗?如果需要更多片段,请告诉我。谢谢。
最佳答案
正在调用的API不支持Put()调用。您应该使用 Post 方法调用
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
}));
}
关于javascript - HTTP PUT 方法返回未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47129804/