【转载】GoLang中http.Get(url)显示unsupported protocol scheme问题

2021.6.29解决来源:
https://studygolang.com/articles/9194
添加http或https即可。


代码如下

package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
    "os"
)

func main() {
    for _, url := range os.Args[1:] {
        resp, err := http.Get(url)
        if err != nil {
            fmt.Fprintf(os.Stderr, "fetch:%v\n", err)
            os.Exit(1)
        }
        b, err := ioutil.ReadAll(resp.Body)
        resp.Body.Close()
        if err != nil {
            fmt.Fprintf(os.Stderr, "fetch:reading %s: %v\n", url, err)
            os.Exit(1)
        }
        fmt.Printf("%s", b)
    }
}

正确运行代码

go run 01.go https://www.baidu.com

你可能感兴趣的:(【转载】GoLang中http.Get(url)显示unsupported protocol scheme问题)