1

I'm using Volley for a GET request to an address on my localhost, but it fails with the error:

Cleartext HTTP traffic to 192.168.1.45 not permitted

I followed the guide here: Android 8: Cleartext HTTP traffic not permitted And did the following:

Created the network security xml file:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">http://192.168.1.45/companyweb/greetings</domain>
    </domain-config>
</network-security-config>

Added it in my manifest and also allowed cleartext traffic:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.omerfaran.myudemyapp">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:networkSecurityConfig="@xml/network_security_config"
        android:usesCleartextTraffic="true"

I'm still getting the same error. Changing from 'http' to 'https' gives this error:

socket failed: EPERM (Operation not permitted)

My code in MainActivity:

val url = "http://192.168.1.45/companyweb/greetings"
val rq = Volley.newRequestQueue(this)
val sr = StringRequest(Request.Method.GET, url, Response.Listener { response ->
    fragmentText.text = response
    Log.d("TAG", "success")
}, Response.ErrorListener { error -> Log.d("TAG", "fail" + error.toString()) })
rq.add(sr)

What can I do next?

Umair Iqbal
  • 1,959
  • 1
  • 19
  • 38
sir-haver
  • 3,096
  • 7
  • 41
  • 85

3 Answers3

3

You should include only the IP address, that is:

<domain includeSubdomains="true">192.168.1.45</domain>
Ryan M
  • 18,333
  • 31
  • 67
  • 74
  • It's not working, when I try I get the error: java.net.SocketException: socket failed: EPERM (Operation not permitted) – sir-haver Feb 06 '20 at 11:02
  • I think it's the same as changing http to https? – sir-haver Feb 06 '20 at 11:02
  • Oh I found the answer, I had to just restart the emulator....You were right about your suggestion, it's actually the same as changing to https in this case, thank you – sir-haver Feb 06 '20 at 11:10
1

I had a similar problem in a recent project, try adding:

android:usesCleartextTraffic="true"

To your AndroidManifext.xml file under the application tag.

0

I found the answer here: java.net.SocketException: socket failed: EPERM (Operation not permitted)

Apparantly what I had to do is restart the emulator (or uninstall the app)

sir-haver
  • 3,096
  • 7
  • 41
  • 85