Last active
May 29, 2024 01:17
-
-
Save narenaryan/64c34d810928abceb6a99c4f6b443a35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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