{"record":{"id":"74a4376e0f660e81","repo":"jeessy2/ddns-go","slug":"v-74a437","errorCode":null,"errorMessage":"创建请求失败: %v","messagePattern":"创建请求失败: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/eranet.go","lineNumber":262,"sourceCode":"\n\treturn strings.Join(finalQuery, \"&\"), nil\n}\n\nfunc (t *Eranet) request(apiPath string, params map[string]string, method string) ([]byte, error) {\n\t// 生成签名\n\tqueryString, err := t.sign(params, method)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"生成签名失败: %v\", err)\n\t}\n\n\t// 构造完整URL\n\tbaseURL := \"https://www.eranet.com\"\n\tfullURL := baseURL + apiPath + \"?\" + queryString\n\n\t// 创建HTTP请求\n\treq, err := http.NewRequest(method, fullURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"创建请求失败: %v\", err)\n\t}\n\n\t// 设置请求头\n\treq.Header.Set(\"Accept\", \"application/json\")\n\n\t// 发送请求\n\tclient := t.httpClient\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"请求失败: %v\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\t// 读取响应\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"读取响应失败: %v\", err)\n\t}","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/eranet.go#L244-L280","documentation":"This error is thrown by Eranet.request when http.NewRequest fails to construct the outgoing HTTP request object for calls to create, modify, or getRecordList. Given the fullURL is already assembled from a constant baseURL, a signed queryString, and a method variable, failure almost always means an invalid HTTP method string or a malformed URL (e.g. unparsable characters in the query string). It wraps the underlying net/url parse error with %v.","triggerScenarios":"http.NewRequest returns an error when the method contains invalid characters or the fullURL fails url.Parse — e.g. a method other than a standard verb with bad characters, or a queryString containing raw spaces/control characters because signing/encoding (util.PercentEncode) produced an unexpected value.","commonSituations":"Misconfigured HTTP method passed down from create/modify; control characters or unencoded spaces in parameter values (API key/secret with trailing whitespace or newline) leaking into the query string; custom API paths containing characters illegal in URLs.","solutions":["Trim and validate the API secret/key and all parameter values for whitespace or control characters before calling create/modify","Verify the method argument is exactly GET or POST (uppercase, no spaces)","Print/inspect the fullURL (it is baseURL+apiPath+\"?\"+queryString) to spot malformed characters","Check util.PercentEncode output for the offending parameter"],"exampleFix":"// before\nreq, err := http.NewRequest(method, fullURL, nil)\n// after\nmethod = strings.ToUpper(strings.TrimSpace(method))\nfullURL = strings.TrimSpace(fullURL)\nreq, err := http.NewRequest(method, fullURL, nil)\nif err != nil {\n    return nil, fmt.Errorf(\"创建请求失败: %v\", err)\n}","handlingStrategy":"validation","validationCode":"method = strings.ToUpper(strings.TrimSpace(method))\nif method != http.MethodGet && method != http.MethodPost {\n    return fmt.Errorf(\"unsupported method: %q\", method)\n}\nfor k, v := range params {\n    if strings.ContainsAny(v, \" \\t\\r\\n\\x00\") {\n        return fmt.Errorf(\"parameter %q contains invalid characters\", k)\n    }\n}","typeGuard":"func isValidMethod(m string) bool {\n    switch strings.ToUpper(strings.TrimSpace(m)) {\n    case http.MethodGet, http.MethodPost:\n        return true\n    }\n    return false\n}","tryCatchPattern":"body, err := eranetClient.CreateRecord(params)\nif err != nil {\n    if strings.Contains(err.Error(), \"创建请求失败\") {\n        // request construction failed: method/URL malformed — fix inputs, no retry\n        return fmt.Errorf(\"eranet request malformed: %w\", err)\n    }\n    return err\n}","preventionTips":["Always pass plain uppercase GET/POST as the method","Trim whitespace from API keys, secrets, and domain values read from config","Never hand-build query strings with raw values; rely on the library's PercentEncode signing","Log the full URL at debug level to catch encoding problems early"],"tags":["http","request-construction","go","url"],"backgroundTag":"invalid-http-request","analyzedSha":"5874c2e6667c69357ab95079421131104bd3fcae","analyzedAt":"2026-09-03T15:41:16.799Z","contentChangedAt":"2026-09-03T15:41:16.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}