Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "io"
- "net/http"
- )
- func main() {
- // Create an HTTP client with default settings
- client := &http.Client{}
- // Make an HTTPS GET request to example.com
- resp, err := client.Get("https://pastebin.com")
- if err != nil {
- fmt.Println("Error:", err)
- return
- }
- defer resp.Body.Close()
- // Print the response body
- fmt.Println(resp.Status)
- fmt.Println(resp.Header)
- // Read the response body and convert it to a string
- bodyBytes, err := io.ReadAll(resp.Body)
- if err != nil {
- fmt.Println("Error:", err)
- return
- }
- bodyString := string(bodyBytes)
- // Print the response body as a string
- fmt.Println(bodyString)
- }
Advertisement