title: CORS policy 'Access-Control-Allow-Origin' (Anguar 8 and Servlet)
body: <p>Getting error while making post request from Angular app to servlet doPost method.</p>
  
  <p>Angular application make 2 request 1 for doGet method and other doPost method.</p>
  
  <p>In doGet method i added following heders as follows</p>
  
  <pre><code>resp.setHeader("Access-Control-Allow-Origin", "*");
  resp.setHeader("Access-Control-Allow-Methods", "GET");
  resp.setHeader("Access-Control-Max-Age", "3600");
  resp.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  </code></pre>
  
  <p>and solved my CORS problem for GET call.</p>
  
  <p>but doPost method give CORS error even i added same header in doPost method.</p>
  
  <p>angular console shows</p>
  
  <pre><code>Access to XMLHttpRequest at 'http://localhost:8080/server/config' 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.
  </code></pre>
  
  <p>Server is written in servlet and running on port 8080.
  Front end is written in Angular 8 and running on port 4200.</p>
  
  <p>How to solve CORS error for post call...</p>
  
  <p>Thanks..</p>