简体   繁体   中英

SSL CA certificate error unity web request to moodle api

I'm trying to get a moodle api token, it's done via a GET request like this: https://your_moodle_domain/login/token.php?username=YOUR_USERNAME&password=YOUR_PASS&service=moodle_mobile_app

through the browser line and other languages like Python and JS, everything works fine and gets a token, but when I try to do it through unity and C#, I get an error:在此处输入图像描述

my code looks something like this:

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

I also tried a workaround to allow all SSL certificates. By the way, everything is fine on my server with an SSL certificate.

I will be very glad if there are any ideas to solve this problem!

The issue is resolved: unity supports HTTPS requests so far only with TLS version up to 1.2. Therefore, we had to downgrade TLS from 1.3 to 1.2 on the server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM