Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!