{"record":{"id":"47ce0bd3ea2cb9ce","repo":"jeessy2/ddns-go","slug":"v-47ce0b","errorCode":null,"errorMessage":"创建请求失败: %v","messagePattern":"创建请求失败: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/nowcn.go","lineNumber":251,"sourceCode":"\n\treturn strings.Join(finalQuery, \"&\"), nil\n}\n\nfunc (t *Nowcn) 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://api.now.cn\"\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":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/nowcn.go#L233-L269","documentation":"After building the signed URL, Nowcn.request calls http.NewRequest; any failure constructing the request (most commonly an invalid method or an unparseable URL) is wrapped as '创建请求失败' (request creation failed). Nothing was sent to the provider.","triggerScenarios":"http.NewRequest errors — malformed fullURL (empty queryString producing a bad URL, control characters in params), or an invalid HTTP method string passed to request().","commonSituations":"Param values containing unencoded special characters/spaces that break the URL, apiPath typo producing an invalid URL, or a refactor passing a wrong method constant.","solutions":["Print fullURL before http.NewRequest to inspect it","URL-encode all param values (url.Values.Encode already escapes; verify sign output is escaped)","Verify the method argument is exactly GET/POST/PUT/DELETE","Ensure apiPath starts with '/' and contains no invalid characters"],"exampleFix":"// before\nreq, err := http.NewRequest(method, fullURL, nil)\nif err != nil {\n    return nil, fmt.Errorf(\"创建请求失败: %v\", err)\n}\n// after\nreq, err := http.NewRequest(method, fullURL, nil)\nif err != nil {\n    return nil, fmt.Errorf(\"创建请求失败 (url=%s, method=%s): %w\", fullURL, method, err)\n}","handlingStrategy":"validation","validationCode":"// Go: ensure params are encoded and method valid before request\nif method != http.MethodGet && method != http.MethodPost {\n    return fmt.Errorf(\"unsupported method: %s\", method)\n}\n// ensure queryString comes from url.Values.Encode() so all values are escaped","typeGuard":"func validURL(u string) bool {\n    parsed, err := url.Parse(u)\n    return err == nil && parsed.Scheme == \"https\" && parsed.Host != \"\"\n}","tryCatchPattern":"body, err := nowcnClient.request(apiPath, params, method)\nif err != nil {\n    if strings.Contains(err.Error(), \"创建请求失败\") {\n        return fmt.Errorf(\"malformed request (check params/method): %w\", err)\n    }\n    return err\n}","preventionTips":["Always URL-encode parameter values before signing/building the query","Validate the method constant at the API boundary","Keep apiPath values as constants, not free-form strings","Unit-test URL construction with special characters in values"],"tags":["dns","http","url","request-construction"],"backgroundTag":"invalid-request-url","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"}