HTTP post 在 postman 上工作但不在 Angular 上工作 2

HTTP post working on postman but not on Angular 2

我有一个模板(点击)触发 addUseCase():

import {Component} from "@angular/core";
import {DataService} from "../shared/data.service";
import {Config} from "../shared/strings";
import {Headers, Http} from "@angular/http";

@Component({
    selector: "add",
    styleUrls: ["add.component.scss"],
    templateUrl: "add.component.html"
})
export class AddComponent {
    public title: string;
    public body: string;

    constructor(private dataService: DataService,
                private http: Http) {
        this.title = "";
        this.body = "";
    }

    public addUseCase() {

        let url = Config.baseUrl + Config.case;
        console.log("url", url); // --> http://localhost:3001/case

        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        let body = JSON.stringify({title:this.title})

    this.http.post(url, body, {headers: headers}).map( res => console.log ("res", res), error => console.log("error", error));
    }
}

在 Postman 中测试后,我得到 node/express 服务器的正确响应。但是当我尝试使用 angular HTTP 发送时,我根本没有收到任何响应,没有错误:

我的 postman 工作,但无法使 angular 2 的 http post 工作:

更新错误:

this.http.post(url, body, {headers: headers})
    .map(res => res.json()).subscribe(data => console.log(data)); //...errors if any
;

错误:

EXCEPTION: Unexpected token W in JSON at position 0ErrorHandler.handleError @ core.umd.js:3462next @ core.umd.js:6924schedulerFn @ core.umd.js:6172SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ core.umd.js:6164onError @ core.umd.js:6388onHandleError @ core.umd.js:6263ZoneDelegate.handleError @ zone.js:236Zone.runTask @ zone.js:157ZoneTask.invoke @ zone.js:335
core.umd.js:3467 ORIGINAL STACKTRACE:ErrorHandler.handleError @ core.umd.js:3467next @ core.umd.js:6924schedulerFn @ core.umd.js:6172SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ core.umd.js:6164onError @ core.umd.js:6388onHandleError @ core.umd.js:6263ZoneDelegate.handleError @ zone.js:236Zone.runTask @ zone.js:157ZoneTask.invoke @ zone.js:335
core.umd.js:3468 SyntaxError: Unexpected token W in JSON at position 0
    at JSON.parse (<anonymous>)
    at Function.Json.parse (http://localhost:3000/vendor.bundle.js:11272:59)
    at Response.Body.json (http://localhost:3000/vendor.bundle.js:12250:30)
    at MapSubscriber.project (http://localhost:3000/main.bundle.js:6202:47)
    at MapSubscriber._next (http://localhost:3000/vendor.bundle.js:23914:36)
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.bundle.js:249:19)
    at XMLHttpRequest.onLoad (http://localhost:3000/vendor.bundle.js:12581:43)
    at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.bundle.js:14882:36)
    at Object.onInvokeTask (http://localhost:3000/vendor.bundle.js:6930:42)
    at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.bundle.js:14881:41)
  -------------   Elapsed: 16 ms; At: Thu Oct 27 2016 08:06:32 GMT-0500 (COT)   -------------  
    at Object.onScheduleTask (http://localhost:3000/polyfills.bundle.js:14537:19)
    at ZoneDelegate.scheduleTask (http://localhost:3000/polyfills.bundle.js:14859:50)
    at Zone.scheduleEventTask (http://localhost:3000/polyfills.bundle.js:14791:40)
    at zoneAwareAddListener (http://localhost:3000/polyfills.bundle.js:15441:15)
    at XMLHttpRequest.addEventListener (eval at createNamedFn (http://localhost:3000/polyfills.bundle.js:15544:18), <anonymous>:3:43)
    at Observable._subscribe (http://localhost:3000/vendor.bundle.js:12624:23)
    at Observable.subscribe (http://localhost:3000/vendor.bundle.js:70:28)
    at Observable._subscribe (http://localhost:3000/vendor.bundle.js:128:29)ErrorHandler.handleError @ core.umd.js:3468next @ core.umd.js:6924schedulerFn @ core.umd.js:6172SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ core.umd.js:6164onError @ core.umd.js:6388onHandleError @ core.umd.js:6263ZoneDelegate.handleError @ zone.js:236Zone.runTask @ zone.js:157ZoneTask.invoke @ zone.js:335
http.umd.js:188 Uncaught SyntaxError: Unexpected token W in JSON at position 0(…)Json.parse @ http.umd.js:188Body.json @ http.umd.js:1166(anonymous function) @ add.component.ts:34MapSubscriber._next @ map.js:77Subscriber.next @ Subscriber.js:89onLoad @ http.umd.js:1497ZoneDelegate.invokeTask @ zone.js:265onInvokeTask @ core.umd.js:6233ZoneDelegate.invokeTask @ zone.js:264Zone.runTask @ zone.js:154ZoneTask.invoke @ zone.js:335

您从未订阅过 Observable。在您这样做之前不会提出任何请求

this.http.post(url, body, {headers: headers})
  .map(res => res.text()).subscribe(data => console.log(data));