我正在尝试使用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工作正常,但我不知道为什么找不到它?希望你们能帮助我。提前谢谢。