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

问题描述 投票:0回答:1

我正在尝试使用 golang 从服务器重新生成令牌 当我在 localhost 中托管此 url 时,我在 chrome 站点中都获得了 rtc 和 rtm 令牌

http://localhost:8080/rte/agora/publisher/uid/1234/

后来尝试用unity连接 这是我统一的网络请求

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)
c# unity3d http-live-streaming glide-golang agora
1个回答
0
投票

听起来协程触发了两次。附加调试器并在 FetchToken 协程内设置一个断点并查看它是否触发两次(并检查调用堆栈以查看来自何处并检查原因)。

© www.soinside.com 2019 - 2024. All rights reserved.