{"record":{"id":"87cfb43e149c8c5b","repo":"chenhg5/cc-connect","slug":"weixin-s-new-request-w","errorCode":null,"errorMessage":"weixin: %s: new request: %w","messagePattern":"weixin: (.+?): new request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/weixin/client.go","lineNumber":83,"sourceCode":"\t\tTimeout:   timeout + 5*time.Second,\n\t\tTransport: tr,\n\t}\n}\n\nfunc randomWechatUIN() string {\n\tvar b [4]byte\n\tif _, err := rand.Read(b[:]); err != nil {\n\t\treturn base64.StdEncoding.EncodeToString([]byte(\"0000\"))\n\t}\n\tu := uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])\n\treturn base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf(\"%d\", u)))\n}\n\nfunc (c *apiClient) post(ctx context.Context, endpoint string, body []byte, timeout time.Duration, label string) ([]byte, error) {\n\turl := c.baseURL + strings.TrimPrefix(endpoint, \"/\")\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"weixin: %s: new request: %w\", label, err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"AuthorizationType\", \"ilink_bot_token\")\n\treq.Header.Set(\"Content-Length\", fmt.Sprintf(\"%d\", len(body)))\n\treq.Header.Set(\"X-WECHAT-UIN\", randomWechatUIN())\n\tif c.token != \"\" {\n\t\treq.Header.Set(\"Authorization\", \"Bearer \"+c.token)\n\t}\n\tif c.routeTag != \"\" {\n\t\treq.Header.Set(\"SKRouteTag\", c.routeTag)\n\t}\n\n\tclient := c.httpClient\n\tif timeout > 0 {\n\t\t// Dedicated client so long-poll does not inherit short Timeout from default client.\n\t\tclient = c.longPollClient(timeout)\n\t}\n","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/weixin/client.go#L65-L101","documentation":"post() fails while constructing the outbound HTTP request with http.NewRequestWithContext, before any network I/O. Given that bodies are plain byte slices and endpoints are simple strings, this almost always indicates a malformed URL — e.g. an empty or invalid baseURL joined with the endpoint.","triggerScenarios":"http.NewRequestWithContext returns an error for the URL c.baseURL+endpoint — typically an unparseable/empty base URL or a context already cancelled with an invalid method/URL combination.","commonSituations":"baseURL misconfigured in config.toml (e.g. missing scheme like 'ilinkai.weixin.qq.com' without https://); whitespace/control characters injected into the URL; empty endpoint constant typo.","solutions":["Check the base_url setting for the weixin platform in config.toml — it must include the scheme (default https://ilinkai.weixin.qq.com)","Print/verify the constructed URL (baseURL+endpoint) when this fires","Ensure endpoint strings have no stray whitespace or invalid characters","Confirm the label in the error to identify which API call (getUpdates/sendMessage/etc.) built the bad request"],"exampleFix":"# before: config.toml\n[platforms.weixin]\nbase_url = \"ilinkai.weixin.qq.com\"   # missing scheme\n# after\n[platforms.weixin]\nbase_url = \"https://ilinkai.weixin.qq.com\"","handlingStrategy":"validation","validationCode":"u := baseURL\nif parsed, err := url.Parse(u); err != nil || parsed.Scheme == \"\" || parsed.Host == \"\" {\n    return fmt.Errorf(\"invalid weixin base_url %q\", u)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include the scheme (https://) in base_url in config.toml","Validate base_url at startup with url.Parse before entering the poll loop","Stick to the default (omit base_url) unless you have a proxy/gateway requirement","Trim whitespace/control characters from configured URLs"],"tags":["http","url","weixin","request-construction"],"backgroundTag":"invalid-url","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}