Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Android POST data to local server using webview error

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>
 
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda