Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda