package main import ( "fmt" "net/http" ) func main() { client := http.Client{} resp, err := client.Head("https://www.google.com") if err != nil { fmt.Println(err) } fmt.Println(resp.Header.Get("Content-Type")) }
package main import ( "fmt" "net/http" ) func main() { client := http.Client{} req, err := http.NewRequest("GET", "https://www.google.com", nil) if err != nil { fmt.Println(err) } req.Header.Set("User-Agent", "My-App") resp, err := client.Do(req) if err != nil { fmt.Println(err) } fmt.Println(resp.Header.Get("Content-Length")) }This code creates a new HTTP request using the `http.NewRequest` function and sets a custom `User-Agent` header on the request. The request is then sent using the `client.Do` method and the response headers are obtained using the `.Header` field on the `resp` object. In this case, we are getting the `Content-Length` header. In both examples, the `net/http` package is being used for HTTP client operations.