title: How to fix 'Cleartext HTTP traffic to x not permitted'
body: <p>I'm trying to make a post request to an http server, but when I try to get an input stream I get the error <code>java.io.IOException: Cleartext HTTP traffic to x not permitted</code></p>
  
  <p>I've already tried putting <code>android:usesCleartextTraffic="true"</code> in my manifest, as well as making a network security config and setting the android:targetSandboxVersion to 1</p>
  
  <p>app/src/main/res/xml/network_security_config.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;network-security-config&gt;
      &lt;domain-config cleartextTrafficPermitted="true"&gt;
          &lt;domain includeSubdomains="true"&gt;Server adress&lt;/domain&gt;
      &lt;/domain-config&gt;
  &lt;/network-security-config&gt;
  </code></pre>
  
  <p>app/src/main/AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.packagename"
      android:targetSandboxVersion="1"&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"
          android:usesCleartextTraffic="true"
          android:networkSecurityConfig="@xml/network_security_config"
          &gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  </code></pre>
  
  <p>Logcat output</p>
  
  <pre><code>D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
  W/System.err: java.io.IOException: Cleartext HTTP traffic to x not permitted
  W/System.err:     at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:124) 
  W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:462)
  W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
  W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:248)
  </code></pre>
  
  <p>Any help would be appreciated</p>