我一直在尝试如何使用英雄联盟API直播。我已经成功地使用了这样的端点:/lol/召唤师/v4/召唤师/按名称/{召唤师名称}
但当涉及到使用这样的端点时(对于实时游戏数据(:GEThttps://127.0.0.1:2999/liveclientdata/allgamedata
我明白错误";无法连接到目标主机">
这是我一直在尝试的示例代码:
private IEnumerator Test()
{
string url = "https://127.0.0.1:2999/liveclientdata/activeplayername";
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
{
yield return webRequest.SendWebRequest();
string error = webRequest.error;
if (error != null)
{
Debug.LogError("[LoLAPI] - " + error);
}
else
{
Debug.Log(webRequest.downloadHandler.text);
}
}
}
我是不是错过了什么?
感谢
UnityWebRequest的实现默认不接受自签名SSL证书。尝试添加以下内容:
public class UncheckedCertificateHandler: CertificateHandler
{
protected override bool ValidateCertificate(byte[] certData)
{
// certificate validation always returns true
return true;
}
}
然后,当您创建web请求时:
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
{
www.certificateHandler = new UncheckedCertificateHandler();
yield return webRequest.SendWebRequest();
或者,如果http://
可用,也可以使用它。