I'm trying to create a basic ability to post comments on a blog, getting the following error for a POST request to my API using Angular2:
Error in comment.service: Response with status: 0 for URL: null
The form submit button calls my comment component, comment-form.component.ts
onSubmit() {
this.submitted = true;
//TODO: replace hardcoded with form fields
this.newComment = new CommentInputViewModel("temp", 0, 0, true, "null", 0);
this.newComment.text = this.model.text;
this.newComment.ownerID = 6;
this.newComment.parentID = 1305;
this.newComment.score = 0.5;
this.newComment.isFact = true;
this.newComment.sideID = 1073;
this.newComment.sideText = "For";
this._postService.postNewComment(this.newComment)
.subscribe(comment => this.returnedComment = comment,
error => this.errorMessage = <any>error);
console.log("commentList.component - After onSubmit:" + this.returnedComment);
return JSON.stringify(this.model);
}
Which calls my service to the API:
postNewComment(newComment: IComment): Observable<IComment>{
let _body = JSON.stringify(newComment);
let _headers = new Headers();
_headers.append( 'Content-Type', 'application/json' );
let _options = new RequestOptions({ headers: _headers });
return this._http.post(this._postNewCommentUrl, _body, _options)
.map((res:Response) => res.json().value)
.catch(this.handleError);
}
The result on the API side, from VS2015 debugger is a 204 error (no content):
]1
What I've tried:
Mostly ruled out COR issues. Most of the other Angular2 POST questions on here were COR problems. Since the request is hitting my Visual Studio debugger and returning 204 I don't think that's it. Plus my CORE startup.cs has "builder.AllowAnyOrigin(); as a policy.
GET commands from the same service to the same API work fine. I can read comments I previously created on the API side.
Intercepting the call with POSTMAN produces the following:
If I modify the POSTMAN request by changing the 'text' to json and pasting in the model, it works fine. It hits the API's "Post" method and returns 200, and the json text "true". See below.
It looks like the body and the headers aren't being transmitted. In the debugger both get passed to the back-end Angular2 code:
As recommended below, here's the dev-tools screencap. Shows pretty much the same thing as POSTMAN.




