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
+7k Golang : Calculate BMI and risk category
+6.8k Golang : Calculate pivot points for a cross
+18k Golang : Qt image viewer example
+8.4k Golang : Check if integer is power of four example
+20.9k Golang : Convert date string to variants of time.Time type examples
+10k Golang : Function wrapper that takes arguments and return result example
+5.3k Golang : Print instead of building pyramids
+9.4k Golang : Temperatures conversion example
+4.7k MariaDB/MySQL : How to get version information
+6.6k Grep : How to grep for strings inside binary data
+14.6k Android Studio : Use image as AlertDialog title with custom layout example
+20.4k Golang : Check if os.Stdin input data is piped or from terminal