Send GET Request using Go

http.Get function

package main

import (
    "fmt"
    "io"
    "log"
    "net/http"
)

func main() {
    response, err := http.Get("https://httpbin.org/get")
    if err != nil {
        log.Fatalln(err)
    }
    defer response.Body.Close()

    body, err := io.ReadAll(response.Body)
    if err != nil {
        log.Fatalln(err)
    }
    content := string(body)

    fmt.Println(content)
}

Leave a Comment

Cancel reply

Your email address will not be published.