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

标签 javascript json angular html-table put

尝试执行 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/

相关文章:

javascript - fadeToggle 与 animate :width? 结合时出现故障

PHP时间间隔至少十天

c# - 通过 Web API 发送的字符串用引号括起来

rest - Angular2 - 显示加载消息,并在异步调用完成后隐藏它

javascript - 使用 *ngIf 作为切换以 Angular 2 显示 div 内容

javascript - Babel 异步等待

javascript - 无法使用从安全嵌入式芯片生成的 WebCrypto API (subtlecrypto) 验证原始 UInt8Array ECDSA (secp256r1) 消息/签名/公钥

javascript - 如何使用不可变的 javascript 模拟状态

json - JSON 中的结构化文本

ajax - Angular/RxJS - 只调用一次 AJAX 请求,否则发出 Observable 的当前值