Why does UnityWebRequest return unkown error when I do a GET request on Linux?

断了今生、忘了曾经 提交于 2020-01-21 09:58:10

问题


This is my code:

public class DatabaseHandler : MonoBehaviour
{

    string url = "https://fakeid.firebaseio.com/";
    void Start()
    {
        StartCoroutine(GetLevelsCoroutine());
    }

    IEnumerator GetLevelsCoroutine()
    {    
        using (UnityWebRequest www = UnityWebRequest.Get(url))
        {
            www.SetRequestHeader("X-Firebase-Decoding", "1");
            yield return www.SendWebRequest();
            if (www.isDone)
            {
                Debug.Log(www.error);
                string result = www.downloadHandler.text;
                Debug.Log(result);
            }
        }
    }


}

The result variable is null and the www.error is "unknown error" I have been trying different things in order to fix this but, I just can't figure out what's causing this error, since it's just a generic error.

I have also read that this may be an unitywebrequest bug, if it is so, are there any alternatives?


回答1:


Finally found the solution to the problem. (It only occurs on some Linux OS)

Unity only officially supports Ubuntu Linux, so it is looking (and failing to find) the certificate store where it would expect it to be. You can work around on Fedora by creating a symbolic link:

mkdir -p /etc/ssl/certs && ln -s /etc/pki/tls/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt

This is the source where I got it from: https://forum.unity.com/threads/ubuntu-headless-build-tls-handshake-fails.546704/




回答2:


It seems like you're trying to get JSON from the Firebase Realtime Database through its REST API. Requests to the REST API must end in .json, otherwise Firebase interprets them as requests to open the console on that location. So UnityWebRequest.Get(url+.json)



来源:https://stackoverflow.com/questions/53597396/why-does-unitywebrequest-return-unkown-error-when-i-do-a-get-request-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!