【问题标题】:HTTP PUT method returns error not foundHTTP PUT 方法返回错误未找到
【发布时间】:2018-04-18 04:40:08
【问题描述】:

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

这是来自 stock.service.ts 文件的 sn-p

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 文件的 sn-p

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);
  }

谁能帮我解决这个错误?如果需要更多的 sn-ps,请告诉我。谢谢。

Link full ts

【问题讨论】:

  • 你能把http;//localhost:3000/Student/改成http://localhost:3000/Student/吗? (注意;:
  • localhost:4200 来自哪里?
  • 我也不知道 localhost:4200 是从哪里来的
  • ;更改为:
  • 那么...它有效吗?

标签: javascript json angular html-table put


【解决方案1】:

被调用的 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
            }));
     }

【讨论】:

  • 很抱歉,我已经有了可以正常工作的发布和删除方法。
猜你喜欢
  • 2015-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-16
  • 1970-01-01
  • 2017-02-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多