Golang net/http.Client.Get() function example
package net/http
Golang net/http.Client.Get() function usage example
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
)
func main() {
client := &http.Client{}
resp, err := client.Get("https://golang.org")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer resp.Body.Close()
htmlData, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(os.Stdout, string(htmlData))
}
See also : https://www.socketloop.com/tutorials/golang-http-get-example
Reference :
Advertisement
Something interesting
Tutorials
+3.9k Golang : Function as an argument type example
+4.8k Golang : Get YouTube playlist
+7.4k Golang : Simple file scaning and remove virus example
+3.1k Fix Google Analytics Redundant Hostnames problem
+5.4k Golang : Progress bar with ∎ character
+5.4k Golang : Find network service name from given port and protocol
+7.1k Golang : Meaning of omitempty in struct's field tag
+6.2k Golang : Find and replace data in all files recursively
+3.2k Golang : Convert an executable file into []byte example
+9.4k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+5.9k Random number generation with crypto/rand in Go