title: ERROR Failed to load resource: the server responded with a status of 403 () en angular
body: <p><a href="https://i.stack.imgur.com/lPZbN.png" rel="nofollow noreferrer"> Errors I get</a></p>
  
  <p>ERRORES:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Failed to load resource: the server responded with a status of 403 ()
  login:1 Access to XMLHttpRequest at 'http://localhost:8080/login' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
  core.js:7187 ERROR Error: Uncaught (in promise): HttpErrorResponse: {"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":"http://localhost:8080/login","ok":false,"name":"HttpErrorResponse","message":"Http failure response for http://localhost:8080/login: 0 Unknown Error","error":{"isTrusted":true}}
      at resolvePromise (zone-evergreen.js:797)
      at zone-evergreen.js:707
      at SafeSubscriber._error (Observable.js:91)
      at SafeSubscriber.__tryOrUnsub (Subscriber.js:183)
      at SafeSubscriber.error (Subscriber.js:135)
      at Subscriber._error (Subscriber.js:75)
      at Subscriber.error (Subscriber.js:55)
      at MapSubscriber._error (Subscriber.js:75)
      at MapSubscriber.error (Subscriber.js:55)
      at FilterSubscriber._error (Subscriber.js:75)
  defaultErrorLogger @ core.js:7187</code></pre>
  </div>
  </div>
  </p>
  
  <p>POST service in JAVA spring boot (url of the microservice: http:localhost:8080/login):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@CrossOrigin(origins = "*")
  @RestController
  public class dmoController {
  
      @SuppressWarnings("rawtypes")
      @PostMapping("/login")
      public ResponseEntity&lt;?&gt; login(@RequestBody String data) {
   System.out.print("entra");
   System.out.print(data);
   HttpHeaders headers = new HttpHeaders();
   headers.add("Access-Control-Allow-Origin", "*");
   headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
   headers.add("Access-Control-Allow-Headers", "X-Requested-With,content-type");
   headers.add("Access-Control-Allow-Credentials", "true");
   return new ResponseEntity&lt;&gt;(headers, HttpStatus.CREATED);
      }
  
      
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Call to post from Angular (url angular: http:localhost:4200/login):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  public async login(email: string, password: string) {
          const data = { username: 'pepa', password: 'manoli' };
  
          httpOptions.headers.append('Access-Control-Allow-Origin', '*');
          httpOptions.headers.append(
              'Access-Control-Allow-Methods',
              'GET, POST, OPTIONS, PUT, PATCH, DELETE',
          );
          httpOptions.headers.append(
              'Access-Control-Allow-Headers',
              'X-Requested-With,content-type',
          );
          httpOptions.headers.append('Access-Control-Allow-Credentials', 'true');
  
          this.http.post(this.url, JSON.stringify(data), httpOptions).toPromise();
      }</code></pre>
  </div>
  </div>
  </p>