title: Angular4 doesn't send post data
body: <p>Angular HttpClient doesnt send data to controller. 
  I get a error 500 (because username in controller is null) when i try to execute fun(). </p>
  
  <p><em>test.sevice.ts</em></p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import {HttpClient} from "@angular/common/http";
  
  import 'rxjs/Rx';
  import { Observable } from 'rxjs/Rx';
  
  @Injectable()
  export class RestService {
  
  private EndPointUrl = 'http://127.0.0.1:8080/api/test';
  
  constructor(public http: HttpClient){}
  
  fun(){
     this.test().subscribe((data)=&gt;console.log(data));
    }
  
  test(): Observable&lt;string&gt;{
     let params = new URLSearchParams();
     params.append("grant_type",'password');
     params.append('username', 'Name');
  
     let body = params.toString();
  
     let headers = new HttpHeaders();
     headers.set('Content-Type', 'application/x-www-form-urlencoded');
  
     return this.http.post&lt;string&gt;(this.EndPointUrl,  body);
    }
  }
  </code></pre>
  
  <p><em>package.json</em></p>
  
  <pre><code> ...
  "dependencies": {
  "@angular/common": "4.3.4",
  "@angular/compiler": "4.3.4",
  "@angular/compiler-cli": "4.3.4",
  "@angular/core": "4.3.4",
  "@angular/forms": "4.3.4",
  "@angular/http": "4.3.4",
  "@angular/common/http": "4.3.4",
  "@angular/platform-browser": "4.3.4",
  "@angular/platform-browser-dynamic": "4.3.4",
  ...},
  </code></pre>
  
  <p>Spring MVC Controller:</p>
  
  <pre><code>@RequestMapping(value="/test", 
                  method = RequestMethod.POST,
                  produces=MediaType.APPLICATION_JSON_VALUE)
  public String[] test(HttpServletRequest request){
      Map&lt;String, String[]&gt; parameters = request.getParameterMap();
      return parameters.get("username");
  }
  </code></pre>
  
  <p>Request from postMan works, and returns some username.</p>
  
  <p>Does anyone know what I'm doing wrong?</p>