title: Angular 7 post request with body and header
body: <p>I am trying to do a post request with body and header. Below are some of the variations I have gone through, but for the most part I am getting error on the server saying that the parameter, 'key', was not passed in.</p>
  
  <p>I tried this api in the postman and it's working there. This is how I have defined the method header in Java/Spring Boot: </p>
  
  <pre><code>@RequestMapping(value = "/getIssue", method = RequestMethod.POST)
  public IssuePojo getIssue(@RequestParam("key") String key, HttpServletRequest request) {
  </code></pre>
  
  <p>Below are my angular's variations:</p>
  
  <pre><code>public getJiraIssue(key: string): Observable&lt;any&gt; {
  
      let headers = new HttpHeaders({
        'Content-Type': 'application/json',
        'Authorization': this.idToken });
      let options = { headers: headers };
  
      const paramsA = new URLSearchParams();
      paramsA.set('key', key);
      let params = new HttpParams().append('key', key);
      // return this.http.post(this.urlEnvironment.jiraGetIssue(), params, this.getHeaders());
      console.log("headers: ", this.getHeaders());
      // let obj = {
      //   key: key
      // }
  
      var headersA = new Headers();
      headers.append('Authorization', this.idToken);
  
      let body = new HttpParams()
      .set('key', key);
  
      return this.http.post(this.urlEnvironment.jiraGetIssue(), body, {headers: headers});
      // return this.http.post(this.urlEnvironment.jiraGetIssue(), null, {headers: this.getHeaders(), params: params});
    }
  </code></pre>
  
  <p>It seems that the body is being sent:</p>
  
  <p><a href="https://i.stack.imgur.com/J5KRo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J5KRo.png" alt="enter image description here"></a></p>
  
  <p>But this is the error I got:</p>
  
  <pre><code>timestamp: "2019-01-30T04:30:40.721+0000", status: 400, error: "Bad Request",…}
  error: "Bad Request"
  message: "Required String parameter 'key' is not present"
  path: "/jira/getIssue"
  status: 400
  timestamp: "2019-01-30T04:30:40.721+0000"
  trace: "org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'key' is not present
  </code></pre>