1

I keep getting errorcode -6 and description net::ERR_CONNECTION_REFUSED on android webview in

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final WebView webview =(WebView) this.findViewById(R.id.webView);

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webview.setWebViewClient(new MyWebViewClient());//I only implemented onReceivedError to display the errors in logcat

    webview.loadUrl("http://mydomainexample.com");// it loads http://google.com but throws error code = -6 for my doamin which works fine in any navigator

}

while the exact same url (example http://aaaaaaaaa.com) works well in any navigator, do webviews make connections differently from navigators? What could be causing this issue?

bkn
  • 21
  • 1
  • 11
  • Post ss of your webview results – Prajwal Waingankar Jan 04 '20 at 19:34
  • ´http://´google.com will auto-redirect to **https**://google.com. What Android version are testing on? The issue might be SSL-related, also check [this question](https://stackoverflow.com/questions/51902629/how-to-allow-all-network-connection-types-http-and-https-in-android-9-pie) – Droidman Jan 06 '20 at 10:41
  • I'm testing on android 8.1.0 – bkn Jan 06 '20 at 15:55
  • I've the proposed solution(adding usesCleartextTraffic) it still gives me the same error – bkn Jan 06 '20 at 18:53
  • Could it be an issue on the server side? the ports 80 and 8080 have been allowed – bkn Jan 06 '20 at 19:01

2 Answers2

0

Maybe due to cookie request by the website (see Android Webview error code -6) but please post your code. There is also a posting on https://github.com/ionic-team/capacitor/issues/1848

Softwar
  • 21
  • 2
  • I don't use cookies, I didn't see any solution to this in the url https://github.com/ionic-team/capacitor/issues/1848 – bkn Jan 06 '20 at 10:34
0

The issue was that the loaded webpage had a js file that, asynchronously, made a request to a port which was blocked on the server. I've tried removing that request and it worked

bkn
  • 21
  • 1
  • 11