发布请求不断获得404代码

时间:2017-05-24 11:35:41

标签: angular

我参与了Angular的英雄之旅教程项目,并希望根据自己的目的修改该代码。我对其中一个服务方法(在hero.service.ts中添加一个名称)进行了一些小改动,以调用一个正在运行的API端点。

create(name: string): Promise<Hero> {
    return this.http
        .post("http://echo.jsontest.com/key/value", JSON.stringify({name: name}), {headers: this.headers})
        .toPromise()
        .then(res => res.json().data as Hero)
        .catch(this.handleError);
}

调用此方法不断给我404响应,Firefox&#39;控制台给出:

13:29:58.821 An error occurred Object { _body: Object, status: 404, ok: false, statusText: "Not Found", headers: Object, type: null, url: "http://echo.jsontest.com/key/value" } 1 hero.service.js:27:9
HeroService.prototype.handleError http://localhost:3000/app/hero.service.js:27:9
ZoneDelegate.prototype.invoke http://localhost:3000/node_modules/zone.js/dist/zone.js:381:17
onInvoke http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:4132:28
ZoneDelegate.prototype.invoke http://localhost:3000/node_modules/zone.js/dist/zone.js:380:17
Zone.prototype.run http://localhost:3000/node_modules/zone.js/dist/zone.js:141:24
scheduleResolveOrReject/< http://localhost:3000/node_modules/zone.js/dist/zone.js:805:52
ZoneDelegate.prototype.invokeTask http://localhost:3000/node_modules/zone.js/dist/zone.js:414:17
onInvokeTask http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:4123:28
ZoneDelegate.prototype.invokeTask http://localhost:3000/node_modules/zone.js/dist/zone.js:413:17
Zone.prototype.runTask http://localhost:3000/node_modules/zone.js/dist/zone.js:181:28
drainMicroTaskQueue http://localhost:3000/node_modules/zone.js/dist/zone.js:574:25
ZoneTask/this.invoke http://localhost:3000/node_modules/zone.js/dist/zone.js:480:25

我甚至无法在网络流量中看到传出的POST请求。我在这里缺少什么?

0 个答案:

没有答案