I installed GeoServer 2.12.1 on windows 8.1 x64 and I am trying to design a custom "login" form using AngularJS5 with Node.js, but when I make a request to geoserver it rejected by CORS, and get the error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/geoserver/rest/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
I read several questions here and follow the steps to enable CORS in geoserver by: downloading the matching "Jetty-Utility Servlets" jar file and putting it in the path:
C:\Program Files (x86)\GeoServer 2.12.1\webapps\geoserver\WEB-INF\lib
and also I uncomment the filters in the web.xml file and then restart geoserver .. but all that not worked with me.
I don't know what is wrong. As I said above I read several post about the problem but no luck.Like this question: Enabling CORS in GeoServer (jetty)?
The Solution:
I used in my request headers, the Authorization header which doesn't allowed by default by CORS, so I added it explicitly in the web.xml file:
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization</param-value>
</init-param>
curl -v -H "Origin: http://example.com" http://localhost:8080/geoserver/wfs\?service\=WFS\&version\=2.0.0\&request\=GetFeature\&typenames\=sf:bugsites\&filter\=%3Cfes:Filter%20xmlns:fes\=%22http://www.opengis.net/fes/2.0%22%3E%3Cfes:ResourceId%20rid\=%22bugsites.3%22/%3E%3C/fes:Filter%3E– Ian Turton Dec 25 '17 at 10:53< HTTP/1.1 404 Not Found < Access-Control-Allow-Origin: http://example.com < Access-Control-Allow-Credentials: true < Access-Control-Expose-Headers: < X-Frame-Options: SAMEORIGIN < Content-Type: text/html; charset=ISO-8859-1 < Cache-Control: must-revalidate,no-cache,no-store < Content-Length: 298 < Server: Jetty(9.2.13.v20150730)`
– abd0991 Dec 25 '17 at 11:15HTTP ERROR 404
Problem accessing /geoserver/wfs\. Reason:
Powered by Jetty://
` – abd0991 Dec 25 '17 at 11:35