{"record":{"id":"cc24bbd062f094b5","repo":"EllanJiang/GameFramework","slug":"web-request-uri-is-invalid","errorCode":null,"errorMessage":"Web request uri is invalid.","messagePattern":"Web request uri is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/WebRequest/WebRequestManager.cs","lineNumber":411,"sourceCode":"        public int AddWebRequest(string webRequestUri, string tag, int priority, object userData)\n        {\n            return AddWebRequest(webRequestUri, null, tag, priority, userData);\n        }\n\n        /// <summary>\n        /// 增加 Web 请求任务。\n        /// </summary>\n        /// <param name=\"webRequestUri\">Web 请求地址。</param>\n        /// <param name=\"postData\">要发送的数据流。</param>\n        /// <param name=\"tag\">Web 请求任务的标签。</param>\n        /// <param name=\"priority\">Web 请求任务的优先级。</param>\n        /// <param name=\"userData\">用户自定义数据。</param>\n        /// <returns>新增 Web 请求任务的序列编号。</returns>\n        public int AddWebRequest(string webRequestUri, byte[] postData, string tag, int priority, object userData)\n        {\n            if (string.IsNullOrEmpty(webRequestUri))\n            {\n                throw new GameFrameworkException(\"Web request uri is invalid.\");\n            }\n\n            if (TotalAgentCount <= 0)\n            {\n                throw new GameFrameworkException(\"You must add web request agent first.\");\n            }\n\n            WebRequestTask webRequestTask = WebRequestTask.Create(webRequestUri, postData, tag, priority, m_Timeout, userData);\n            m_TaskPool.AddTask(webRequestTask);\n            return webRequestTask.SerialId;\n        }\n\n        /// <summary>\n        /// 根据 Web 请求任务的序列编号移除 Web 请求任务。\n        /// </summary>\n        /// <param name=\"serialId\">要移除 Web 请求任务的序列编号。</param>\n        /// <returns>是否移除 Web 请求任务成功。</returns>\n        public bool RemoveWebRequest(int serialId)","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/WebRequest/WebRequestManager.cs#L393-L429","documentation":"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.","triggerScenarios":"Calling AddWebRequest(null), AddWebRequest(\"\"), or AddWebRequest with a uri variable that is null/empty at call time.","commonSituations":"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.","solutions":["Validate/trim the URI before calling AddWebRequest; ensure string.IsNullOrWhiteSpace(webRequestUri) is false.","Verify config/remote data holding the URL is loaded before issuing requests.","Fix the code path that builds the URL so the host+path are always populated."],"exampleFix":"// before\nstring url = config.GetUrl(assetName); // returns null on missing key\nint serialId = m_WebRequestManager.AddWebRequest(url);\n// after\nstring url = config.GetUrl(assetName);\nif (string.IsNullOrEmpty(url))\n{\n    Log.Warning(\"No URL configured for {0}\", assetName);\n    return;\n}\nint serialId = m_WebRequestManager.AddWebRequest(url);","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrWhiteSpace(webRequestUri))\n{\n    int serialId = m_WebRequestManager.AddWebRequest(webRequestUri, postData);\n}","typeGuard":"bool IsValidWebRequestUri(string uri) => !string.IsNullOrWhiteSpace(uri) && (Uri.TryCreate(uri, UriKind.Absolute, out var u) || uri.Contains(\"://\"));","tryCatchPattern":"try\n{\n    int serialId = m_WebRequestManager.AddWebRequest(webRequestUri);\n}\ncatch (GameFrameworkException ex) when (ex.Message == \"Web request uri is invalid.\")\n{\n    Log.Error(\"Rejected web request: uri was null or empty.\");\n}","preventionTips":["Centralize URL construction in one helper that validates non-empty output.","Fail fast (log a clear error) when config keys backing URLs are missing.","Add a startup assertion that required remote-address config is loaded before any request."],"tags":["csharp","gameframework","webrequest","uri","null-argument"],"backgroundTag":"invalid-url","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}