I send text data to the server with the following code:

import {Injectable} from '@angular/core'; import {HTTP_PROVIDERS, Http, Response, Headers, RequestOptions} from "@angular/http"; import {Observable} from 'rxjs/Rx'; @Injectable() export class DemoService { constructor(private http:Http) { } createFood() { let headers = new Headers({'Content-Type': 'application/json'}); let options = new RequestOptions({headers: headers}); let date = { id: 1, name: "Test" }; let body = JSON.stringify(date); return this.http.post('http://server.com.ua/api', body, headers).map((res:Response) => res.json()); } } 

On the server, I check the $ _POST array (to the file and to the mail) and there "[]" (empty);

  • what version of angular? - Grundy
  • JSON.stringify you can not do - Grundy
  • @Grundy 2.0.0-rc.1 - Arzek
  • I advise you to upgrade to the release version. There on the way to her there were several breaking changes - Grundy

1 answer 1

 let options = new RequestOptions({headers: headers}); 

I suspect that this variable should be passed to the request.

  • By the way, the idea was that the console should have had a lot of errors due to incorrect transmission - Grundy