When using “http
” package in golang, you should use the full domain name, For example:
package main
import (
"net/http"
"fmt"
"io/ioutil"
"os"
)
func main() {
resp, err := http.Get("www.google.com")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
text, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(string(text))
}
Executing it, the error will be:
Get www.google.com: unsupported protocol scheme ""
Add “http://
” before “www.google.com
“, then executing it. The result is OK:
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta co....
P.S., the full code is here.
Thanks!! Worked!
thanks!
Thanks Dude !!!
THAAANKS! 😀
great, works!
POST? not work to me… GET is OK
Thaaaaanks! You saved my life
God, you literally saved me! Thanks!
Thanks a bunch!!
Quick and easy description and solution, thanks mate!
Awesome
Could you please share the full code how it is working
package main
import (
"net/http"
"fmt"
"io/ioutil"
"os"
)
func main() {
resp, err := http.Get("http://www.google.com")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
text, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(string(text))
}
Thanks! waste time before your suggest