0

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: enter image description here

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!

President James K. Polk
  • 40,516
  • 21
  • 95
  • 125
Pprog
  • 1
  • 1

2 Answers2

0

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

Pprog
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 06 '22 at 03:10
-1

Unfortunately, the same problem is not in the editor, but is already noticeable in the assembled application.

  • it seems that it is not answer of question. – Pradeep Kumar Oct 27 '22 at 09:54
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33032219) – Marcelo Scofano Diniz Nov 01 '22 at 18:42