Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Last active May 29, 2024 01:17
Show Gist options
  • Save narenaryan/64c34d810928abceb6a99c4f6b443a35 to your computer and use it in GitHub Desktop.
Save narenaryan/64c34d810928abceb6a99c4f6b443a35 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
"time"
)
func main() {
client := &http.Client{Timeout: 5 * time.Second}
// Create a new request
req, err := http.NewRequest("GET", "https://httpbin.org/get", nil)
if err != nil {
fmt.Println(err)
return
}
// Attach headers to the request
req.Header.Add("User-Agent", "go-http-client")
req.Header.Add("Content-Type", "application/json")
// Make a HTTP request
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resp.StatusCode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment