{"record":{"id":"449c4614504096db","repo":"fish2018/pansou","slug":"create-request-failed-page-d-w","errorCode":null,"errorMessage":"create request failed (page %d): %w","messagePattern":"create request failed \\(page (.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/hunhepan/hunhepan.go","lineNumber":211,"sourceCode":"\t\t\t\t\"adv_params\": map[string]interface{}{\n\t\t\t\t\t\"wechat_pwd\": \"\",\n\t\t\t\t\t\"platform\":   \"pc\",\n\t\t\t\t},\n\t\t\t}\n\n\t\t\tjsonData, err := json.Marshal(reqBody)\n\t\t\tif err != nil {\n\t\t\t\tdebugLog(\"序列化请求失败 (page %d): %v\", pageNum, err)\n\t\t\t\terrChan <- fmt.Errorf(\"marshal request failed (page %d): %w\", pageNum, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tdebugLog(\"发送请求到 %s (page %d): %s\", apiURL, pageNum, string(jsonData))\n\n\t\t\treq, err := http.NewRequest(\"POST\", apiURL, bytes.NewBuffer(jsonData))\n\t\t\tif err != nil {\n\t\t\t\tdebugLog(\"创建请求失败 (page %d): %v\", pageNum, err)\n\t\t\t\terrChan <- fmt.Errorf(\"create request failed (page %d): %w\", pageNum, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t\t\treq.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36\")\n\t\t\treq.Header.Set(\"Accept\", \"application/json, text/plain, */*\")\n\t\t\treq.Header.Set(\"Accept-Language\", \"zh-CN,zh;q=0.9,en;q=0.8\")\n\n\t\t\t// 根据不同的API设置不同的Referer\n\t\t\tif strings.Contains(apiURL, \"qkpanso.com\") {\n\t\t\t\treq.Header.Set(\"Referer\", \"https://qkpanso.com/search\")\n\t\t\t} else if strings.Contains(apiURL, \"kuake8.com\") {\n\t\t\t\treq.Header.Set(\"Referer\", \"https://kuake8.com/search\")\n\t\t\t} else if strings.Contains(apiURL, \"hunhepan.com\") {\n\t\t\t\treq.Header.Set(\"Referer\", \"https://hunhepan.com/search\")\n\t\t\t} else if strings.Contains(apiURL, \"misoso.cc\") {\n\t\t\t\treq.Header.Set(\"Referer\", \"https://www.misoso.cc/search\")\n\t\t\t\treq.Header.Set(\"Origin\", \"https://www.misoso.cc\")","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/hunhepan/hunhepan.go#L193-L229","documentation":"After marshaling, the plugin builds the POST with http.NewRequest. Failure means the request could not be constructed — almost always a malformed apiURL (unparseable URL) since the body is a valid bytes.Buffer.","triggerScenarios":"http.NewRequest(\"POST\", apiURL, bytes.NewBuffer(jsonData)) returns an error for a given page — typically apiURL contains invalid characters, spaces, or an unsupported scheme.","commonSituations":"API endpoint constant containing whitespace/fullwidth characters or a wrong scheme (missing http://), URL built by string concatenation with unescaped keyword, misconfigured base URL in plugin config.","solutions":["Log the wrapped error and print apiURL to spot invalid characters or a missing scheme","Use url.Parse(apiURL) beforehand to validate the endpoint URL","Build the URL with url.Values / url.Build to escape the keyword properly (url.QueryEscape)","Fix the API endpoint constant/config value that produces the malformed URL"],"exampleFix":"// before\nreq, err := http.NewRequest(\"POST\", apiURL, bytes.NewBuffer(jsonData))\nif err != nil {\n\terrChan <- fmt.Errorf(\"create request failed (page %d): %w\", pageNum, err)\n\treturn\n}\n// after\nif _, perr := url.Parse(apiURL); perr != nil {\n\terrChan <- fmt.Errorf(\"invalid api URL %q: %w\", apiURL, perr)\n\treturn\n}\nreq, err := http.NewRequest(\"POST\", apiURL, bytes.NewBuffer(jsonData))\nif err != nil {\n\terrChan <- fmt.Errorf(\"create request failed (page %d): %w\", pageNum, err)\n\treturn\n}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(apiURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n\t// endpoint URL invalid; fix config before calling the plugin\n}","typeGuard":"func isValidURL(s string) bool {\n\tu, err := url.Parse(s)\n\treturn err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"create request failed\") {\n\tlog.Printf(\"bad endpoint URL: %v\", err) // fix the apiURL constant/config\n}","preventionTips":["Validate endpoint URLs with url.Parse at plugin startup","Escape user keywords with url.QueryEscape when embedding in URLs","Avoid building URLs by raw string concatenation; use url.Values","Keep endpoint constants free of whitespace or fullwidth characters"],"tags":["http","url","request-construction"],"backgroundTag":"invalid-url","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}