{"record":{"id":"f4355244f1398e19","repo":"egametang/ET","slug":"http-request-fail-link-substring-0-link-indexof-f43552","errorCode":null,"errorMessage":"http request fail: {link.Substring(0,link.IndexOf('?'))}\\n{e}","messagePattern":"http request fail: (.+?)\\\\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.loader/Scripts/Loader/Share/HttpClientHelper.cs","lineNumber":27,"sourceCode":"    {\n        public static async ETTask<string> Get(string link)\n        {\n            try\n            {\n#if UNITY_WEBGL // 这里只能限制WEBGL, 因为NetClient Fiber会调用，如果改成UNITY会导致不是在主线程使用\n                UnityEngine.Networking.UnityWebRequest req = UnityEngine.Networking.UnityWebRequest.Get(link);\n                await req.SendWebRequest();\n                return req.downloadHandler.text;\n#else\n                using HttpClient httpClient = new();\n                HttpResponseMessage response =  await httpClient.GetAsync(link);\n                string result = await response.Content.ReadAsStringAsync();\n                return result;\n#endif\n            }\n            catch (Exception e)\n            {\n                throw new Exception($\"http request fail: {link.Substring(0,link.IndexOf('?'))}\\n{e}\");\n            }\n        }\n    }\n}","sourceCodeStart":9,"sourceCodeEnd":31,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.loader/Scripts/Loader/Share/HttpClientHelper.cs#L9-L31","documentation":"Thrown by HttpClientHelper.Get as a catch-all wrapping any exception during an HTTP GET. It strips the query string from the URL for the message (everything before '?') and appends the inner exception. Note: if the URL contains no '?', link.IndexOf('?') returns -1, and link.Substring(0, -1) itself throws ArgumentOutOfRangeException, masking the real error.","triggerScenarios":"Calling HttpClientHelper.Get with a URL that is unreachable, returns a non-success HTTP status, has DNS resolution failure, or has a network timeout. On WebGL builds, UnityWebRequest.SendWebRequest() failing (network error, CORS, invalid URL).","commonSituations":"Wrong server address or port in config. Server is down or behind a firewall. DNS not resolving in the build environment. URL missing '?' query separator causes a secondary Substring crash. SSL/TLS certificate issues on the target endpoint.","solutions":["Verify the URL is reachable from the runtime environment (correct host, port, scheme, no firewall blocking).","If the URL legitimately has no query string, note that the Substring(0, IndexOf('?')) in the catch will itself throw — patch HttpClientHelper.Get to use a safe index: link.Substring(0, link.IndexOf('?') >= 0 ? link.IndexOf('?') : link.Length).","Check server logs and network connectivity (firewall rules, DNS resolution, TLS cert validity)."],"exampleFix":"// before\nthrow new Exception($\"http request fail: {link.Substring(0,link.IndexOf('?'))}\\n{e}\");\n// after: guard against missing '?'\nint qIdx = link.IndexOf('?');\nstring safeUrl = qIdx >= 0 ? link.Substring(0, qIdx) : link;\nthrow new Exception($\"http request fail: {safeUrl}\\n{e}\");","handlingStrategy":"try-catch","validationCode":"// Validate URL before calling HttpClientHelper.Get\nif (string.IsNullOrWhiteSpace(link) || !Uri.TryCreate(link, UriKind.Absolute, out _))\n{\n    Log.Error($\"Invalid URL for HttpClientHelper.Get: {link}\");\n    return null;\n}","typeGuard":null,"tryCatchPattern":"try { string result = await HttpClientHelper.Get(link); } catch (Exception e) { Log.Error($\"HTTP GET failed for {link}: {e.Message}\"); /* fallback or retry */ }","preventionTips":["Always validate URLs with Uri.TryCreate before passing to HttpClientHelper.Get.","Be aware the catch block will itself throw if the URL has no '?' character — patch HttpClientHelper.Get to guard IndexOf.","Implement retry-with-backoff for transient network failures rather than failing on first attempt."],"tags":["network","http","loader","webgl"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}