I have a local server with a static IP 192.168.1.3:8080 hosted geoserver using appach tomcat, I want to send a gps data from my phone to Geoserver, which also has a static IP "192.168.1.233:8080", The android application side is a simple webview, I use loadURL function to load html and java script that using 'POST' to push data to server.
The webpage and Js code work perfect (no syntax error or throw..etc)
String JSCODE = "<!DOCTYPE html><html> <head> TEST <script>"+JSCODE_nonhtml+ "</script> </head> </html>";
WebView _wbv = (WebView)findViewById(R.id.mywebview);
_wbv.getSettings().setJavaScriptEnabled(true);
_wbv.getSettings().setAllowUniversalAccessFromFileURLs(true);
_wbv.getSettings().setAllowFileAccessFromFileURLs(true);
_wbv.getSettings().setGeolocationEnabled(true);
_wbv.loadDataWithBaseURL("", JSCODE, "text/html", "utf-8", null);
When i launch the application I get this error:
I/chromium: [INFO:CONSOLE(0)] "Access to XMLHttpRequest at 'http://192.168.1.3:8080/geoserver/wfs' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.", source: about:blank (0)
I know there is CORS problem, so how i can fix this both on android and PC server. thanks in advance.
EDIT I Added the following command to
C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\web.xml
of the tomcat server configuration
<filter>
<filter-name>httpHeaderSecurity</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<async-supported>true</async-supported>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<url-pattern>/*</url-pattern>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
</filter>