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

168
Visualizações
Send XHR request from html file wrapped into webview using javascript

I have index.html file it contains CSS,HTML and JavaScript code JavaScript code is sending request using XMLHttpRequest to .php file on the server, .php file echoing some data.

I wrap HTML code into android app WebView as string (not using loadUrl function) using code that i found on this source

Java:

// Create an unencoded HTML string
// then convert the unencoded HTML string into bytes, encode
// it with Base64, and load the data.
String unencodedHtml =
     "<html><body>'%23' is the percent code for ‘#‘ </body></html>";
String encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(),
        Base64.NO_PADDING);
myWebView.loadData(encodedHtml, "text/html", "base64");

Also enabled Internet and JavaScript support

<manifest ... >
    <uses-permission android:name="android.permission.INTERNET" />
    ...
</manifest>

webSettings.setJavaScriptEnabled(true);

But i can't send GET/POST request from JavaScript inside app to remote .php file on server.

Everything is working if i upload index.html file to server and send request to .php file I can send request without CORS issue from localhost too.

Is there any way to avoid wrapp entire Website into WebView and use loadUrl instead of loadData function or am i missing something?

Can i send XHR/Fetch requests from app to server and receive data into WebView?

I am still searching for answer but still not found working solution

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