I have an WebView that loads an local html file (auth.html).
auth.html has main.js included, which needs to make AJAX POST & GET requests.
The Problem
When a request is made, i always get an ERR_CONNECTION_TIMED_OUT. It's not a server problem because the requests work great in the website.
MainActivity.java
package com.netwok.global;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.clearCache(true);
myWebView.clearHistory();
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.getSettings().setAppCacheEnabled(false);
myWebView.setWebContentsDebuggingEnabled(true);
myWebView.loadUrl("file:///android_asset/home.html");
myWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
}
Any help is appreciated