title: Angular 4 http CORS No 'Access-Control-Allow-Origin' with a java servlet
body: <p>I'm trying to do a http.post but chrome is showing the following error: </p>
  
  <blockquote>
    <p>No Access-Control-Allow-Origin.</p>
  </blockquote>
  
  <p>My Angular function is:</p>
  
  <pre><code>onSubmit(event: Event) {
    event.preventDefault();
      this.leerDatos()
      .subscribe(res =&gt; {
        //datos = res.json();
        console.log("Data send");
      }, error =&gt; {
            console.log(error.json());
        });
  
  
  
    }
  
    leerDatos(): Observable&lt;any&gt; {
      let headers = new Headers({ 'Content-Type': 'application/json' });
      let options = new RequestOptions({ headers: headers });
  
      return this.http.post(`http://localhost:8080/LegoRepositoryVincle/CoreServlet`, { name: "bob" }, options)
                      //.map(this.extractData)
                      //.catch(this.handleError);
    }
  </code></pre>
  
  <p>And my servlet doPost method includes: </p>
  
  <pre><code>response.setContentType("application/json");
  response.setCharacterEncoding("utf-8");
  response.addHeader("Access-Control-Allow-Origin","http://localhost:4200");
  response.addHeader("Access-Control-Allow-Credentials", "true");
  response.addHeader("Access-Control-Allow-Methods","GET,POST");
  response.addHeader("Access-Control-Allow-Headers","X-PINGOTHER, Origin, X-Requested-With, Content-Type, Accept, Cache-Control, Pragma");
  </code></pre>