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