- Home /
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.
=======================
Your "update date" is one month into the future ^^. Note that important parts are missing in your question. Especially which protocol you're using. $$anonymous$$any platforms recommend / restrict web traffic to SSL encrypted connections and refuse unsecure connections such as plain text http. Even when using https, self-signed certificates are not considered secure and may also cause the connection to be refused.
Since this informations is hidden in your "fullUrl" we can't be sure if that's the issue.
@Bunny83 Thanks for your reply - update date corrected. I've added an url similar to the one I use in the app. I use http protocol - this is only a prototype app. The server is running a Ruby On Rails backend on heroku. Note that the EXACT same application works when built to Android API level 27, but fails with level 28. No modifications. I wonder if it's some new security settings / requirements in the new Android API. $$anonymous$$aybe my app needs to request more access to network or something.....
Answer by Bunny83 · Jun 22, 2019 at 02:43 PM
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.
That really sounds like a plausible solution! thanks. I'm gonna look into it tomorrow and post back here! $$anonymous$$uch appreciated!
@Bunny83 I think definitely you are correct. I've been reading up on the changes in Android 9. I'm thinking either to go for your suggestion (allow http) or try to allow un-signed certificates (until I get a proper one) by using this strategy: https://answers.unity.com/questions/1482409/how-to-accept-self-signed-certificate.html
Would you like to post your answer as a "real" answer, so I can mark it "correct"?
Your answer
Follow this Question
Related Questions
[ASP.NET] [WEB API] Problem with HttpWebRequest.ContentType 0 Answers
UriFormatException: Invalid URI: Invalid port number for VirtualBox server using IPv6 Address 1 Answer
UnityWebRequest object downloadhandler.text not returning same/all data compared to browser 0 Answers
can we send data to GET api?,can we send data to get type api ? 0 Answers
Unable to call external API (IBM Watson) via HTTP request? 1 Answer