Reputation: 79
I am building an angular2 app and I am pretty new at angular2. I am trying to make a post request but as an answer from the server, I got 500 INTERNAL SERVER ERROR and Response for preflight has invalid HTTP status code 500. However for the post request that I have made without the body, I don't get any error, and I was able to get the correct response from the server.
Here are my service method and corresponding component.ts method. The code below shows the service.ts file.
SomeCoolMethod(input: HTMLInputElement) {
let headers = new Headers({'Content-Type': 'application/json'});
let options = new RequestOptions({headers: headers});
let param = {'name': input.value};
return this.http.post('fancyURL/SomeCoolMethod', param, options)
.map(this.extractData);
}
private extractData(res: Response) {
return res.json();
}
The code below shows the component.ts file.
SomeCoolMethod(input: HTMLInputElement) {
this.httpService.SomeCoolMethod(input).subscribe(response => {
console.log(response)
});
}
I know that 500 Internal Server Error is because of the server. But when I make the same request to the server via Advanced Rest Client, it gave no such error. Is there anyone who knows the problem? I think I am setting parameters in an incorrect way but I couldn't find how to fix it. Can you help me with this one?
Thanks in advance.
Upvotes: 0
Views: 7040