Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CORS filter gives 403 in POST only in Chrome

I have following configuration in Tomcat. I get 403 error when making POST requests from my local machine browser to remote server. I use EASYUI JQuery components, and they work fine on IE10+ and Firefox! Only chrome is complaining this. Can any one hep?

  <filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>
like image 561
Rashmin H Gadhavi Avatar asked Mar 16 '15 19:03

Rashmin H Gadhavi


1 Answers

Had the same problem when sending a JSON object via POST, and solved by explicitly setting a JSON content type header:

var config = { headers: {
    'Content-Type': 'application/json'
    }
};

$http.post(url, config)
.success
...

It seems Chrome is unable to automatically detect the Content Type as well as Firefox etc. can.

like image 200
James Avatar answered Nov 11 '22 08:11

James