go config_error ai_generated true

error: unsupported protocol scheme "ftp"

ID: go/http-unsupported-protocol-scheme

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-04-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.21 active

Root Cause

http.Get或http.NewRequest使用了非HTTP/HTTPS的URL方案,如ftp或file。

generic

中文

http.Get或http.NewRequest使用了非HTTP/HTTPS的URL方案,如ftp或file。

Workarounds

  1. 90% success
    检查并修正URL:
    if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {
        url = "http://" + url
    }
  2. 85% success
    使用url.Parse验证方案:
    parsed, err := url.Parse(rawURL)
    if err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") {
        // 处理错误
    }

Dead Ends

Common approaches that don't work:

  1. 90% fail

    http包不处理ftp,需要更换库。

  2. 100% fail

    请求永远不会成功。