title: CORS with AngularJS and JAX-RS
body: <p>I am writing a web application using AngularJS on the front end and JAX-RS on the backend. The front end can make HTTP post requests successfully to the backend when the CORS extension in chrome has 'enable CORS' on. When it is off, it comes back with an error - </p>
  
  <p>The 'Access-Control-Allow-Origin' header contains multiple values '<a href="http://127.0.0.1:XYZXX" rel="nofollow">http://127.0.0.1:XYZXX</a>, *', but only one is allowed. Origin '<a href="http://127.0.0.1:XYZXX" rel="nofollow">http://127.0.0.1:XYZXX</a>' is therefore not allowed access.</p>
  
  <p>The backend has a CORSFilter.java file configured as below -</p>
  
  <p>public class CORSFilter  implements ContainerResponseFilter {</p>
  
  <pre><code> @Override
      public ContainerResponse filter(ContainerRequest request,
          ContainerResponse response) {
  
          response.getHttpHeaders().add("Access-Control-Allow-Origin", "*");
          response.getHttpHeaders().add("Access-Control-Allow-Headers",
              "origin, content-type, accept, authorization");
          response.getHttpHeaders().add("Access-Control-Allow-Credentials","true");
          response.getHttpHeaders().add("Access-Control-Allow-Methods",
              "GET, POST, PUT, DELETE, OPTIONS, HEAD");
  
          return response;
      }
  </code></pre>
  
  <p>}</p>
  
  <p>I have tried suggestions in various stackoverflow posts like deleting the X-REQUESTED-WITH and setting UseXDomain to true -</p>
  
  <p>delete $http.defaults.headers.common['X-Requested-With'];
  $http.defaults.useXDomain = true;</p>
  
  <p>I have also tried changing the content-type to Form/URLEncoded instead of Application/JSON. None seem to enable sending the POSTs except the Chrome extension - which makes me think the solution should be on client side.</p>
  
  <p>Please help! - Thanks in advance.</p>