Www request not working on Android P

Hi everyone, I have my game pulling a bunch of data from my server just using a standard www request as below (just part of my code).

WWW wwwLogin = new WWW (url);
            StartCoroutine (WaitForRequestLogin (wwwLogin));

Everything works fine on all Android and iOS devices I’ve tested on. But I’ve had a few users who just got on to Android P who have told me the game no longer works. So I’ve got an emulator running on my pc and sure enough the game does nothing. The www request returns no data or no errors at least from what I can tell printing results to the screen of the phone.

So my question is, have they changed something in Android Pie? Does the WWW request work differently? Do i need new permissions in the manifest? Do I need to upgrade to the newest version of unity for Android P?

Hopefully someone can shed some light on this for me.

Cheers

Is anyone able to pull data with a simple request in the Android P emulator?

I’ve even started a new project and in the editor, pre-android p and ios can pull basic data from a server. But then I deploy this new project to the Android P emulator and get “Unknown error” returned, no matter how I approach it or what server I access

Is there any info in logcat?

Guess: you are trying to access a non-secure URL, and it’s now prohibited in Android 9 Pie.

2 Likes

What is the way around if we want to use a legacy non-secure url?
Currently by default all non-secure URLs are being rejected by P which is breaking the game.

Also, if we change the URLs to https, will it affect older versions of Android? I read somewhere that https is not supported below API 20? We are using:

WWWForm form = new WWWForm();
form.AddField(“playername”, SaveManager.Instance.state.PlayerId);
form.AddField(“platform”, “android”);
form.AddField(“userid”, SaveManager.Instance.state.SocialId);

WWW www = new WWW(“https://www.serverurl.com/request.php”, form);

Any inputs would be great!

1 Like

Looking at Unity code I see that TLS 1.1 and 1.2 are supported since API 16, but they are enabled by default since API 20. However, we do enable them, so API 16 and higher is fine. If your site uses TLS 1.0, I suppose you could go even lower, but please do some research on that.

I have a game on store which reads and displays data from web using same http url and is working fine on my Android P.

But when I build an update in Unity 2018.2 it does not read the same url in Android P but working fine on other devices below P

Hi
that’s happened with me also.

try to change Target Api Level to Android 8.1 ‘Oreo’ (Api level 27) instead of Automatic (highest installed).

it worked for me , i hope the same for you

(Sorry for my bad english )

4 Likes

Thanks mate it did worked.

(Your English is not bad)

1 Like

Finally, that’s great

This is a bad solution - everyone can intercept your communication.

I’m expecting by the end of this year Google will require target SDK to be set to 28 for the apps submitted to Google Play: Android Developers Blog: Improving app security and performance on Google Play for years to come

A good solution is to switch to https.

1 Like

There is another solution. Instead of using UnityWebRequest, you can use the HttpClient from .Net with UniRx.
Here is an example of a get request:

Also you can caсhe HttpClient in your local variable.
And in this solution you can use http uri.

Just add below line in android manifest.
android:usesCleartextTraffic=“true”

For ex.

1 Like

Thanks This Solved my issue
But what will happen to Android 9 users

1 Like

thank you very much ,i slove this problem

1 Like

i am also facing the similar problems. Suppose if i set target api level toAndroid 8.1 will it works for Android 9…

@anon_98314255 Microsoft… How did you solve the problem… Did it works in Android 9…

1 Like

Here’s another post. Use CleartextTraffic true or switch to https - Android: Cleartext HTTP traffic not permitted Android 9 - Leo N - Medium

I had a mobile with andorid 9.0 and had this problem and with this solution has been fixed
thank you very much!!!1

2 Likes

It really works!
Thanks a lot

1 Like