【问题标题】:SSL CA certificate error unity web request to moodle apiSSL CA证书错误统一Web请求到moodle api
【发布时间】:2022-11-11 12:42:52
【问题描述】:

我正在尝试获取 moodle api 令牌,它是通过这样的 GET 请求完成的: https://your_moodle_domain/login/token.php?username=YOUR_USERNAME&password=YOUR_PASS&service=moodle_mobile_app

通过浏览器行和 Python 和 JS 等其他语言,一切正常并获得令牌,但是当我尝试通过 unity 和 C# 进行操作时,出现错误:

我的代码看起来像这样:

    using System.Collections;
    using System.Collections.Generic;
    using System.Net;using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.Networking;
    public class testReqests : MonoBehaviour{

    public string url = "https://your_moodle_domen/login/token.php?username=YOUR_USERNAMEr&password=YOUR_PASS&service=moodle_mobile_app";

    void Start()
    {
        StartCoroutine(LoadFromServer(url));
    }

    IEnumerator LoadFromServer(string url)
    {
        // var cert = new ForceAcceptAll();
        UnityWebRequest request = UnityWebRequest.Get(url);
        // request.certificateHandler = cert;

        yield return request.SendWebRequest();
        if(request.isNetworkError){
            Debug.Log(request.error);
        } else
        Debug.Log(request.downloadHandler.text); 
        // cert?.Dispose();
    }}

    public class ForceAcceptAll : CertificateHandler{ protected override bool ValidateCertificate(byte[] certificateData)
    {
        return true;
    }
}

我还尝试了一种解决方法来允许所有 SSL 证书。顺便说一句,我的服务器上的一切都很好,有 SSL 证书。

如果有任何想法可以解决这个问题,我将非常高兴!

【问题讨论】:

  • 您当前的代码不处理证书。

标签: c# unity3d ssl moodle moodle-api


【解决方案1】:

问题已解决:到目前为止,unity 仅支持 TLS 版本高达 1.2 的 HTTPS 请求。因此,我们不得不在服务器上将 TLS 从 1.3 降级到 1.2

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:

不幸的是,同样的问题不在编辑器中,但在组装的应用程序中已经很明显了。

【讨论】:

    猜你喜欢
    • 2017-12-11
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 2015-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多