Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cleartext http traffic not permitted [duplicate]

I'm working in one project and I'm stuck in the implementation of login/signup page. When I try to implement the code it gives me the error Cleartext HTTP traffic to 192.168.1.130 not permitted. I checked the ipconfig and that was my IPv4 so I have added 192.168.1.130, but I have also checked 127.0.0.1, but that one doesn't work either.

I have tried implementing <domain includeSubdomains="true">192.168.1.130</domain> however that one doesn't work(implementation of android:usesCleartextTraffic="true" doesn't work either).

I'm using XAMPP for the back-end and if I run php code everything works good, so no problem with that. Problem is in the Android Studio(I'm using Kotlin).

For the Emulator I'm using Genymotion emulator(it uses VirtualBox).

Here's the code for the button that takes the url. I have checked everything, but still nothing achieved.

login.setOnClickListener {
            var url = "http://192.168.1.130/php/login.php?mobile=" + login_user.text.toString() +
                    "&password=" + login_password.text.toString()
like image 224
Nijat Mursali Avatar asked Feb 22 '19 00:02

Nijat Mursali


People also ask

How do you fix cleartext traffic for all domains?

you cannot allow cleartext traffic as the default. this is what occurs when you add the cleartext macro to your manifest. you have to remove that line from the manifest and create your own network security config file. in it you will add a list of url's for which your app permits cleartext.

What is cleartext network traffic?

Cleartext is any transmitted or stored information that is not encrypted or meant to be encrypted. When an app communicates with servers using a cleartext network traffic, such as HTTP, it could raise a risk of eavesdropping and tampering of content. If you are using the https, then no worry about this issue.

How do I enable cleartext?

If your application must support loading plain http:// URLs, you can opt into enabling cleartext traffic by using an AndroidManifest. xml file that includes an android:usesCleartextTraffic="true" application attribute.


2 Answers

To do this in Android 9 Pie you will have to set a networkSecurityConfig in your Manifest application tag like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
     <application android:networkSecurityConfig="@xml/network_security_config">
     </application>
</manifest>

Then create a xml file named network_security_config just like the way you have named it in the Manifest and the content of your file should be like this👇to enable all requests without encryptions:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

If this is not working, please make your request from a secure domain(HTTPS).

like image 187
Shafi Muhammed Avatar answered Oct 04 '22 19:10

Shafi Muhammed


Add this into your Manifest

android:usesCleartextTraffic="true"

like this..

<application
    android:icon="@mipmap/ic_launcher"
    android:usesCleartextTraffic="true"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
...
 </application>
like image 25
Rahul Avatar answered Oct 04 '22 20:10

Rahul