title: How to setup CORS in angular latest cli version
body: <p>What is the right way in production for doing CORS thing in the latest version?  </p>
  
  <p><strong>My function</strong>:</p>
  
  <pre><code> public fetchData() {
      console.log("GET WITH HEADERS");
  
  
      return this.http.get('http://192.168.31.73:8080/myjersey/rest/hello/dd').map(
        (response) =&gt; response
      )
        .subscribe(
        (data) =&gt; console.log(data)
        )
    }
  
    public authentication(email, password) {
      console.log("POST WITH HEADERS");
      const body = { name: 'Brad' };
  
      this.http
        .post('http://192.168.31.73:8080/myjersey/rest/hello/dd', {
          email: email,
          password: password
  
        }, {
          headers: new HttpHeaders().set('Access-Control-Allow-Origin', '*')
            .set('Access-Control-Allow-Credentials', 'true')
            .set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE')
            .set('Access-Control-Allow-Headers', 'X-Custom-Header'),
        })
        .subscribe();
  
  
    }
  </code></pre>
  
  <p>below is the exception I am getting:</p>
  
  <pre><code>Failed to load http://192.168.31.73:8080/myjersey/rest/hello/dd: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
  </code></pre>
  
  <p>Somehow my Http Get is working but not POST.Please suggest what should i do in this case i have added Access-Control-Allow-Origin in both request and response still getting CORS issue.</p>
  
  <p>PS: I have no knowledge of PHP. I am using Jersey Rest Services with angular.</p>
  
  <p><a href="https://i.stack.imgur.com/vgraM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vgraM.png" alt="this is response body from server "></a>
  <a href="https://i.stack.imgur.com/0GITs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0GITs.png" alt="this is response header from server"></a></p>