gpt4 book ai didi

javascript - HTTP PUT 方法返回未找到错误

转载 作者:行者123 更新时间:2023-12-03 03:06:50 26 4
gpt4 key购买 nike

尝试执行 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);
}

谁能帮我解决这个错误吗?如果需要更多片段,请告诉我。谢谢。

Link full ts

最佳答案

正在调用的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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com