【问题标题】:Why does UnityWebRequest return unkown error when I do a GET request on Linux?为什么我在 Linux 上执行 GET 请求时 UnityWebRequest 返回未知错误?
【发布时间】:2018-12-03 16:00:31
【问题描述】:

这是我的代码:

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);
            }
        }
    }


}

结果变量为空,www.error 为“未知错误” 我一直在尝试不同的方法来解决这个问题,但是我无法弄清楚是什么导致了这个错误,因为它只是一个通用错误。

我也读到这可能是一个 unitywebrequest 错误,如果是这样,是否有任何替代方案?

【问题讨论】:

  • 也可能是身份验证错误或服务器内部错误。您还应该检查 www.responseCode 以查看您实际遇到的错误类型。
  • www.responseCode 返回 0
  • 所以也许你的服务器甚至没有找到/没有响应那个 url
  • 是的,你是对的,事实上它适用于 www.google.com,我正在关注这个:firebase.google.com/docs/reference/rest/database/…
  • 真的有理由反对使用firebase SDK吗?

标签: linux firebase unity3d web firebase-realtime-database


【解决方案1】:

终于找到了解决问题的办法。 (它只发生在某些 Linux 操作系统上)

Unity 仅正式支持 Ubuntu Linux,因此它正在寻找(但未能找到)它所期望的证书存储区。您可以通过创建符号链接来解决 Fedora 问题:

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

这是我的来源:https://forum.unity.com/threads/ubuntu-headless-build-tls-handshake-fails.546704/

【讨论】:

    【解决方案2】:

    您似乎正在尝试通过 Firebase 实时数据库的 REST API 获取 JSON。对 REST API 的请求必须以 .json 结尾,否则 Firebase 会将它们解释为在该位置打开控制台的请求。所以UnityWebRequest.Get(url+.json)

    【讨论】:

    猜你喜欢
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多