UnityWebRequest - error: 415 Unsupported Media Type

Hello.

I’m preparing my game for publishing on ArmorGames.com
I use their [API ](https://forum.unity.com/https: //armorgames.readme.io/docs/2_authentication_service#section-parameters) to get the id of the current user:
https://services.armorgames.com/services/rest/v1/authenticate/user.json

When I click on this link in the browser, I get the correct answer.
When sending a GET request through my build, I get an error: HTTP / 1.1 415 Unsupported Media Type

IEnumerator GetText (Action <string> callback)
{
 
        string url;
        url = "https://services.armorgames.com/services/rest/v1/authenticate/user.json";

        UnityWebRequest www = UnityWebRequest.Get (url);
        www.SetRequestHeader ("Content-Type", "application/json");
     
        yield return www.SendWebRequest ();

        if (www.isNetworkError || www.isHttpError) {
            Debug.Log ("MyError:" + www.error);
            callback (null);
        }
        else {
         
                Debug.Log ("resp:" + www.downloadHandler.text);
                callback (www.downloadHandler.text);
        }
    }

What could be the problem?
I tried both with the addition of “Content-Type”, “application/json”, and without. The result is the same.

Your code seems to have some spaces in it that shouldn’t be there. For example, if you got to the web address:

https://services.armorgames.com/services/rest/v1/authenticate/user. json

you will get the error you mentioned.

If you remove the space between user. and json it works ok

https://services.armorgames.com/services/rest/v1/authenticate/user.json

p.s. ‘application / json’ shouldn’t have spaces either - try it with ‘application/json’

1 Like

It’s copy/past spaces. I don’t have them in my code. There should be another problem.

Sorry. You are right.
I thought that forum layout make this spaces.
But there is invisible space in VScode.
Thank you. Now all works fine!

1 Like