How to allow HTTP-connections (not HTTPS) in WebView on Android?

Viewed 7413

I have a WebView application on Android and I want to fetch data from a resource which uses HTTP only. To do so, I use XMLHttpRequest API in JavaScript.

When I fetch data from any other HTTPS-resource, everything is OK. But HTTP never works. How can I fix that?

Is there any way to allow HTTP-connections using JavaScript?

1 Answers

android:usesCleartextTrafficThe default value for apps that target API level 27 or lower is true. Apps that target API level 28 or higher default to false. here

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
   <uses-permission android:name="android.permission.INTERNET" />
   <application
     ...
     android:usesCleartextTraffic="true"
     ...>
     ...
   </application>
</manifest>
Related