【发布时间】: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