title: Angular 2 http post params and body
body: <p>I'm trying to do an API call from my angular app. What I want to do is send a post request to the API with a command param. I have done a lot of server-side testing as well as going through the outgoing request, and the <code>$_POST</code> nor <code>body</code> data is never there. I am therefore pretty sure that the problem lays within this piece of code.</p>
  <pre class="lang-js prettyprint-override"><code>public post(cmd: string, data: object): Observable&lt;any&gt; {
      const params = new URLSearchParams();
      params.set('cmd', cmd);
      
      const options = new RequestOptions({
        headers: this.getAuthorizedHeaders(),
        responseType: ResponseContentType.Json,
        params: params,
        body: data,
        withCredentials: false
      });
      
      console.log('Options: ' + JSON.stringify(options));
      
      return this.http.post('http://t2w.dev/index.php', data, options)
        .map(this.handleData)
        .catch(this.handleError);
  }
  </code></pre>
  <p>I have tried many different JSON structures as <code>data</code> but this is the core of what I am trying to send:</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;Username&quot;: &quot;No thanks&quot;,
      &quot;Password&quot;: &quot;Donno&quot;
  }
  </code></pre>
  <p><code>this.handleData</code> and <code>this.handleError</code> is a method taking data and error as arguments, and returns just what I want.</p>
  <p>The API is setup to log anything coming through <code>$_POST</code> which works fine when running requests from anywhere but my angular app. What I have done so far:</p>
  <ol>
  <li>Passing raw query instead of <code>URLSearchParams</code>.</li>
  <li>Passing the request without body.</li>
  <li>Passing all values in RequestOptions.</li>
  <li>Passing params as a string.</li>
  <li>Passing body as params.</li>
  <li>Passing body as <code>JSON.stringify({ &quot;Username&quot;: &quot;No thanks&quot;, &quot;Password&quot;: &quot;Donno&quot; }</code></li>
  </ol>
  <blockquote>
  <h3>Console output of <code>RequestOptions</code></h3>
  </blockquote>
  <p><code>Options: {&quot;method&quot;:null,&quot;headers&quot;:{&quot;Content-Type&quot;:[&quot;application/json&quot;],&quot;Accept&quot;:[&quot;application/json&quot;],&quot;X-CLIENT-ID&quot;:[&quot;380954038&quot;],&quot;X-CLIENT-SECRET&quot;:[&quot;5BgqRO9BMZ4iocAXYjjnCjnO7fHGN59WP8BTRZ5f&quot;]},&quot;body&quot;:&quot;{}&quot;,&quot;url&quot;:null,&quot;params&quot;:{&quot;rawParams&quot;:&quot;&quot;,&quot;queryEncoder&quot;:{},&quot;paramsMap&quot;:{}},&quot;withCredentials&quot;:false,&quot;responseType&quot;:1} VM8529:1 XHR finished loading: POST &quot;http://t2w.dev/index.php&quot;.</code></p>
  <p>Does anyone have any clue why the data never gets sent?</p>