EllanJiang/GameFramework · error · GameFrameworkException

Web request uri is invalid.

Error message

Web request uri is invalid.

What it means

WebRequestManager.AddWebRequest throws GameFrameworkException with 'Web request uri is invalid.' when the webRequestUri argument is null or an empty string. A web request cannot be issued without a target URI, so the manager validates it before creating the task.

Solutions

  1. Validate/trim the URI before calling AddWebRequest; ensure string.IsNullOrWhiteSpace(webRequestUri) is false.
  2. Verify config/remote data holding the URL is loaded before issuing requests.
  3. Fix the code path that builds the URL so the host+path are always populated.

Example fix

// before
string url = config.GetUrl(assetName); // returns null on missing key
int serialId = m_WebRequestManager.AddWebRequest(url);
// after
string url = config.GetUrl(assetName);
if (string.IsNullOrEmpty(url))
{
    Log.Warning("No URL configured for {0}", assetName);
    return;
}
int serialId = m_WebRequestManager.AddWebRequest(url);
Defensive patterns

Strategy: validation

Validate before calling

if (!string.IsNullOrWhiteSpace(webRequestUri))
{
    int serialId = m_WebRequestManager.AddWebRequest(webRequestUri, postData);
}

Type guard

bool IsValidWebRequestUri(string uri) => !string.IsNullOrWhiteSpace(uri) && (Uri.TryCreate(uri, UriKind.Absolute, out var u) || uri.Contains("://"));

Try / catch

try
{
    int serialId = m_WebRequestManager.AddWebRequest(webRequestUri);
}
catch (GameFrameworkException ex) when (ex.Message == "Web request uri is invalid.")
{
    Log.Error("Rejected web request: uri was null or empty.");
}

Prevention

When it happens

Trigger: Calling AddWebRequest(null), AddWebRequest(""), or AddWebRequest with a uri variable that is null/empty at call time.

Common situations: Server address read from config was empty or not yet loaded (config load order issue); string concatenation produced an empty path; a download URL was never assigned to the data object being used.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/cc24bbd062f094b5. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/WebRequest/WebRequestManager.cs:411

        public int AddWebRequest(string webRequestUri, string tag, int priority, object userData)
        {
            return AddWebRequest(webRequestUri, null, tag, priority, userData);
        }

        /// <summary>
        /// 增加 Web 请求任务。
        /// </summary>
        /// <param name="webRequestUri">Web 请求地址。</param>
        /// <param name="postData">要发送的数据流。</param>
        /// <param name="tag">Web 请求任务的标签。</param>
        /// <param name="priority">Web 请求任务的优先级。</param>
        /// <param name="userData">用户自定义数据。</param>
        /// <returns>新增 Web 请求任务的序列编号。</returns>
        public int AddWebRequest(string webRequestUri, byte[] postData, string tag, int priority, object userData)
        {
            if (string.IsNullOrEmpty(webRequestUri))
            {
                throw new GameFrameworkException("Web request uri is invalid.");
            }

            if (TotalAgentCount <= 0)
            {
                throw new GameFrameworkException("You must add web request agent first.");
            }

            WebRequestTask webRequestTask = WebRequestTask.Create(webRequestUri, postData, tag, priority, m_Timeout, userData);
            m_TaskPool.AddTask(webRequestTask);
            return webRequestTask.SerialId;
        }

        /// <summary>
        /// 根据 Web 请求任务的序列编号移除 Web 请求任务。
        /// </summary>
        /// <param name="serialId">要移除 Web 请求任务的序列编号。</param>
        /// <returns>是否移除 Web 请求任务成功。</returns>
        public bool RemoveWebRequest(int serialId)

View on GitHub (pinned to d0c010b051)