Rob L
Rob L

Reputation: 2372

Xamarin: Java.IO.IOException Message=Cleartext HTTP traffic to myapi.azurewebsites.net not permitted

I recently upgraded to the latest version of Xamarin 4.5.0.356. This forced me to change my Android build version to 9.0.

Since then, whenever I call my test Api I get:

Java.IO.IOException   Message=Cleartext HTTP traffic to myapi.azurewebsites.net not permitted

I realise that API's should all be httpS but this is a test one (owned by me).

I searched the web (stack overflow) and it was suggested that I add the following to AndroidManifest.xml

  <uses-permission android:name="android.permission.INTERNET" />
  <application android:networkSecurityConfig="@xml/network_security_config" />
</manifest>

and then add a Resources/xml/network_security_config.xml file containing the following:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">myapi.azurewebsites.net</domain>
  </domain-config>
</network-security-config>

However, I still get the error on the first call to the API. (iOS version works fine)

Anyone have any ideas?

Upvotes: 2

Views: 1681

Answers (1)

Lia
Lia

Reputation: 523

Try add a base-config in your network_security_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <base-config cleartextTrafficPermitted="true" />
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">myapi.azurewebsites.net</domain>
  </domain-config>
</network-security-config>

Upvotes: 2

Related Questions