title: How to fix 415 Unsupported Media Type for Rest API between Angular 7 and Java
body: <p>This is the first time i developed Java Rest API. I m trying to integrate REST API in Angular 7 but i m getting an error. </p>
  
  <p><strong>415 Unsupported Media Type</strong></p>
  
  <pre><code>package org.jasyatra.controller;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  import org.jasyatra.model.AdminLogin;
  import org.jasyatra.model.LoginAuthToken;
  import org.jasyatra.service.AdminLoginService;
  import org.jasyatra.service.LoginAuthTokenService;
  
  @RestController
  public class AdminLoginController {
  
      @Autowired
      AdminLoginService adminLoginService;
  
      @Autowired
      LoginAuthTokenService loginAuthTokenService;
  
      @RequestMapping(value = "/admin/login", method = RequestMethod.POST, headers = "Accept=application/json")
      public Map login(@RequestBody AdminLogin parameters) {
          List&lt;AdminLogin&gt; loginResponse = adminLoginService.login(parameters);
          Map&lt;String, String&gt; response = new HashMap&lt;&gt;();
          if (loginResponse.size() &gt; 0) {
              response.put("result", "true");
              response.put("id", Integer.toString(loginResponse.get(0).getId()));
              response.put("username", loginResponse.get(0).getUsername());
              response.put("role", loginResponse.get(0).getUserRole());
              List&lt;LoginAuthToken&gt; responseToken = loginAuthTokenService.getLatestToken(loginResponse.get(0).getId(), loginResponse.get(0).getUserRole());
              response.put("token", responseToken.get(0).getToken());
          } else {
              response.put("result", "false");
              response.put("message", "Invalid username or password!");
          }
          return response;
      }
  }
  
  adminLogin(params) {
      let headers = new Headers();
      headers.append('Accept', 'application/json');
      headers.append('Content-Type', 'application/x-www-form-urlencoded');
      let options = new RequestOptions({ headers: headers });
  
      return this.http.post(this.api_url+'/admin/login', params, options).pipe(map((response: any) =&gt; response.json()));
  }
  </code></pre>
  
  <p>If i don't send content-type in headers, i m getting this error:</p>
  
  <pre><code>Request Method: OPTIONS
  Status Code: 403 Forbidden
  </code></pre>
  
  <p>If i send content-type in headers, i m getting this error:</p>
  
  <pre><code>415 Unsupported Media Type
  </code></pre>
  
  <p>I have tried these kind of combinations but looks like none of them is working for me. </p>
  
  <p>Can you please guide me in right direction.</p>
  
  <p>Thanks</p>