UnityWebRequest returning responseCode 0 and isNetworkError == true for Unity 2019

From my Android app I execute a http PUT request with JSON:

String fullUrl = "http://myserver.com/mycontroller/loginJson.json";

UnityWebRequest www = UnityWebRequest.Put(fullUrl,json);

www.SetRequestHeader("Content-Type", "application/json");

yield return www.SendWebRequest();

This code works fine when building with Unity 2018.4.1f1. But if I build with Unity 2019.1.6f1 I get:

www.error : "Unknown"
www.responseCode: 0
www.isNetworkError: true
www.isHttpError: false
www.downloadHandler.text : ""

When I run this code directly in unity, it works fine, and I have no problems communicating with the server. Only building to Android in Unity 2019.1 doesn't work. I also tried the new 2019.3.0a5, and there the Android version also works. This is quite a mystery.

Anyone have any idea what's going on?

=== UPDATE 2019-06-22 ===
I’ve found that it’s probably not related to Unity, but to the Android SDK. If I build with API level 27 (8.1), it works fine, but with API level 29 (9.0), I get the “Unknown Error”. I’ll continue to look into this.

It’s probably a security setting. Though as I said many companies try to push https as the standard in the web Many still allow http but show a warning.

Have you actually tried looking at the log? (logcat)

ps: I just had a look at the update notes

Network TLS enabled by default

If your app needs to enable cleartext
for specific domains, you must
explicitly set
cleartextTrafficPermitted to true for
those domains in your app’s Network
Security Configuration.

So you might need something like:

<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">your.domain.name.com</domain>
    </domain-config>
</network-security-config>

Though another option is to just get a free Lets Encrypt certificate and use https. Note that Lets Encrypt certificates need to be refreshed every 3 month, however this can be automated on the server. I’ve done it on my raspberry pi.