http.put:离子2中的“404未找到”

时间:2017-11-11 15:18:37

标签: json angular http ionic2

我正在尝试使用http.put更新API中的一些数据,但我总是得到“404 not found”。这是我的代码:

TS文件:

activate(customer) {

if(this.mycode==this.cuscode) {
  let headers = new Headers({ 'Content-Type': 'application/json' });
  let options = new RequestOptions({ headers: headers });
  let body = JSON.stringify(customer);

  this.http.put('http://myApi.com/customer/' + this.id, body, options )
  .map(res => res.json())
  .subscribe(data => {
      console.log("Successfully Activated your Account.");
  }, (err) => {
      console.log("ERROR: " +err);
  });
}else {
  this.wrongcode = true;
  console.log("NOT ACTIVATED! Incorrect code mate.");
}

}

HTML文件:

<ion-item [(ngModel)]="mycode">
          <ion-input type="text" placeholder="Activation Code" required></ion-input>
</ion-item>
    <button ion-button (click)="activate(customer)"><ion-icon name="check"></ion-icon>Activate Now</button>

我收到此错误:

 PUT http://myApi/customer/72 404 (Not Found)

我的API工作正常,但我不知道为什么找不到它?希望你们能帮助我。提前谢谢。

1 个答案:

答案 0 :(得分:0)

尝试从提前休息客户端看到这样的选项,如果你有暴露的put方法,它将在高级休息客户端显示“put”该网址

it must also return out for you