title: post request with bearer token in ionic 2 (angular 2)
body: <p>I'm trying to make a post request from an ionic2 project to a server that needs in header a bearer token.</p>
  
  <pre><code>var headers = new Headers();
  headers.append('Authorization', 'Bearer '+mytoken);
  let options = new RequestOptions({ headers: headers });
  
  let body = [
    {key: 'vid',     value: myvid},
    {key: 'start_time',    value: date.toISOString()}
  ].map(x =&gt; `${encodeURI(x.key)}=${encodeURI(x.value)}`).join('&amp;');
  
  return this.http.post(mybasisurl, body, options)
        .map((res: Response) =&gt; res.json())
        .toPromise();
  </code></pre>
  
  <p>but it doesn't work at all. I get 400 (Bad Request) and more specifically:</p>
  
  <pre><code>{"_body":"{\"success\":false,\"description\":\"vid not set\",\"error\":601}","status":400,"ok":false,"statusText":"Bad Request","headers":{"content-type":["application/json"]},"type":2,"url":"myurl"}
  </code></pre>
  
  <p>I have used something similar in a normal post request without the bearer token and it was working correctly:</p>
  
  <pre><code>    var headers = new Headers();
  headers.append('Content-Type', 'application/x-www-form-urlencoded' );
  let options = new RequestOptions({ headers: headers });
  
  let body = [
    {key: 'email',     value: email},
    {key: 'password',    value: password}
  ].map(x =&gt; `${encodeURI(x.key)}=${encodeURI(x.value)}`).join('&amp;');
  
  
  return this.http.post(myurl, body, options)
        .retry(NUM_HTTP_RETRIES)
        .map((res: Response) =&gt; res.json())
        .toPromise();
  </code></pre>
  
  <p>Any suggestions?</p>