I have a spring MVC API backend with the correct CORS setting when I try to make an ajax call, I get the following error in chrome
XMLHttpRequest cannot load 172.20.16.45:8082/cuponza. The request was redirected to "172.20.16.45:8082/cuponza/", which is forbidden for cross-origin requests that require preliminary verification.
My js code is here:
$scope.sendRegistrationForm = function(){ var config = {headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods' : 'GET,OPTIONS', 'Access-Control-Allow-Headers' : 'X-Requested-With, Content-Type', 'Content-Type' : 'text/plain', 'Accept-Language' : 'en-US' } }; $http.get("172.20.16.45:8082/cuponza",config). success(function(data){ alert(data); }). error(function(data,status){ alert(status); }) }
I tried to run chrome with the flag - disable-web-security , and by doing this, I could correctly see that my server side of CorsFilter was working correctly, I also received the correct answer from the server, so I put my error on the client side. when you start chrome, usually the filter on the server never works.
UPDATE: when I delete the configuration object with cors headers, I get the following error
XMLHttpRequest cannot load 172.20.16.45:8082/cuponza . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' localhost:8100' is therefore not allowed access
UPDATE II im showing queries as shown by chrome: initial chrome usually:
OPTIONS / cuponza HTTP / 1.1 Host: 172.20.16.45:8082 Connection: save life Access-control-request method: GET Origin: localhost: 8100 User-Agent: Mozilla / 5.0 (Windows NT 6.1; WOW64) AppleWebKit / 537.36 (KHTML, e.g. Gecko) Chrome / 36.0.1985.143 Safari / 537.36 Access-Control-Request-Headers: access-control-allow-origin, accept-language, access-control-allow-headers, access-control-allow-methods Accept: / Referer: localhost: 8100 / Accept-Encoding: gzip, deflate, sdch Accept-Language: en-US, en; q = 0.8
launch chrome in -disable-web-security mode
GET / cuponza HTTP / 1.1 Host: 172.20.16.45:8082 Connection: save life Access-Control-Allow-Origin: * Accept-language: en-US Access-Control-Allow-Headers: X-Requested-With, Content-Type User-Agent: Mozilla / 5.0 (Windows NT 6.1; WOW64) AppleWebKit / 537.36 (KHTML, e.g. Gecko) Chrome / 36.0.1985.143 Safari / 537.36 Access-Control-Allow-Methods: GET, OPTIONS Accept: / Referer: localhost: 8100 / Accept-Encoding: gzip, deflate, sdch