title: How do I POST JSON in Angular 2?
body: <p>I don't understand what I am doing wrong, my server returns "undefined" when I try to get the json.</p>
  
  <pre><code>POST(url, data) {
          var headers = new Headers(), authtoken = localStorage.getItem('authtoken');
          headers.append("Content-Type", 'application/json');
  
          if (authtoken) {
          headers.append("Authorization", 'Token ' + authtoken)
          }
          headers.append("Accept", 'application/json');
  
          var requestoptions = new RequestOptions({
              method: RequestMethod.Post,
              url: this.apiURL + url,
              headers: headers,
              body: data
          })
  
          return this.http.request(new Request(requestoptions))
          .map((res: Response) =&gt; {
              if (res) {
                  return { status: res.status, json: res.json() }
              }
          });
      }
  </code></pre>
  
  <p>And my function:</p>
  
  <pre><code>login(username, password) {
          this.POST('login/', {test: 'test'}).subscribe(data =&gt; {
              console.log(data)
          })
      }
  </code></pre>
  
  <p>When I try this, the request body looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/tUAQ5.png"><img src="https://i.stack.imgur.com/tUAQ5.png" alt="enter image description here"></a></p>
  
  <p>So instead of sending actual json, it just sends "[object Object]".
  Instead of "Request payload" it should be "JSON". What am I doing wrong?</p>