unity3d 已发送UnityWebRequest;无法再次开始发送请求

dtcbnfnu  于 2023-03-13  发布在  其他
关注(0)|答案(1)|浏览(538)

我正在尝试使用golang从服务器重新生成令牌当我在localhost中托管此URL时,我在chrome站点http://localhost:8080/rte/agora/publisher/uid/1234/中获得了rtc和rtm令牌
后来我尝试连接到Unity这是我在Unity中的webrequest

public static class HelperClass
{
    public static IEnumerator FetchToken(string url, string channel, int userId, Action<string> callback = null) 
    {
        Debug.Log("Hitting Web Request");
        UnityWebRequest request = UnityWebRequest.Get(string.Format("{0}/rtc/{1}/publisher/uid/{2}/", url, channel, userId));
           
        yield return request.SendWebRequest();

        if (request.isNetworkError || request.isHttpError) 
        {
            Debug.Log("request"+request.error);
            callback(null);
            yield break;
        }

       TokenObject tokenInfo = JsonUtility.FromJson<TokenObject>(request.downloadHandler.text);

        callback(tokenInfo.rtcToken);
    }
}

这是我的网址我试图得到

internal static string _tokenBase = "http://localhost:8080/rte/agora/publisher/uid/";

我用

StartCoroutine(HelperClass.FetchToken(_tokenBase, _channelName, 0, this.RenewOrJoinToken));

我尝试获取自动生成令牌,但遇到以下问题

InvalidOperationException: UnityWebRequest has already been sent; cannot begin sending the request again
UnityEngine.Networking.UnityWebRequest.SendWebRequest () (at /Users/bokken/buildslave/unity/build/Modules/UnityWebRequest/Public/UnityWebRequest.bindings.cs:266)
Agora.Util.HelperClass+<FetchToken>d__0.MoveNext () (at Assets/Agora-RTC-Plugin/API-Example/Tools/RequestToken.cs:27)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
k97glaaz

k97glaaz1#

听起来协程被触发了两次。连接调试器并在FetchToken协程内设置断点,看看它是否触发了两次(并检查调用堆栈,看看从哪里触发并检查原因)。

相关问题