Hello, I have trouble with WebRequest on WebGL.
I have the code below.
It is working on Unity editor, but when I build it into WebGL, it doesn’t work.
There is no error running during the Unity editor.
I tested with the forecast API and it did work on WebGL with the same code just changing the URL.
Is it the authority type of problem happening between the code and API?
Do I have to add codes to get the return from the API?
string Best_Move()
{
string url = "https://17xn1ovxga.execute-api.ap-northeast-1.amazonaws.com/production/gikou?byoyomi=1&position=sfen ln5+Pl/3s1kg+R1/p2ppl2p/2ps1Bp2/P8/2P3P1P/N2gP4/5KS2/L+r3G1N+b b GS3Pn3p 57";
StartCoroutine(Get (url));
IEnumerator Get (string url)
{
UnityWebRequest request = new UnityWebRequest();
request.downloadHandler = new DownloadHandlerBuffer();
request.url = url;
request.SetRequestHeader("Content-Type" , "application/json; charset=UTF-8");
request.method = UnityWebRequest.kHttpVerbGET;
yield return request.Send();
if (request.isNetworkError)
{
Debug.Log(request.error);
}
else
{
if (request.responseCode == 200)
{
Debug.Log ("success" + request.responseCode);
string bestmove_text = request.downloadHandler.text;
int pos = bestmove_text.IndexOf ("bestmove");
bestmove = bestmove_text.Substring (pos + 11, 5);
if (bestmove.IndexOf("+") == -1)
{
bestmove = bestmove_text.Substring (pos + 11, 4);
}
}
else
{
//errorFlag = true;
Debug.Log("failed");
}
}
}
return bestmove;