I'm doing some POST requests from my angular js app to my RESTful API implemented using RestEasy.
The case is that I need CORS so I added a servlet filter with this code:
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) res; response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.addHeader("Access-Control-Max-Age", "3600"); response.addHeader("Access-Control-Allow-Headers", "Content-Type"); chain.doFilter(req, res); } But I can't figure out why it works only with GET requests and not POST requests, the error on chrome's console is:
No 'Access-Control-Allow-Origin' header is present on the requested resource
My POST request is:
$http({method: 'POST', url: myUrl, data: $scope.data, headers: {'Content-Type': 'application/json'} }); This is the reponse I receive on POST:
Allow:POST, OPTIONS Content-Length:0 Date:Thu, 03 Apr 2014 23:27:22 GMT Server:Apache-Coyote/1.1 Any Idea? Thanks!
EDIT:
Tested on IE10 and it works but doesn't work on chrome neither firefox ... any body knows why?
Content-Typeheader. try and remove that.