```go
package main
import(
"fmt"
"net/http"
"compress/gzip"
)
func main() {
url := "https://blog.csdn.net/yjp19871013/article/details/82555417"
client := &http.Client {};
req, err := http.NewRequest("GET", url, nil);
if (nil != err) {
return;
}
req.Header.Add("Accept-Encoding", "gzip, deflate");
resp, err := client.Do(req)
if (nil != err) {
return;
}
defer resp.Body.Close();
if 200 == resp.StatusCode {
a := resp.Header
for k,
v := range a {
fmt.Println(k, v)
}
fmt.Println(resp.Header.Get("Content-Encoding"));
reader, _ := gzip.NewReader(resp.Body)
for {
buf := make([] byte, 1024)
n,err := reader.Read(buf)
if nil != err {
return;
}
if 0 == n {
return ;
}
fmt.Println(string(buf))
}
} else {
fmt.Println(resp.StatusCode)
}
}
```
有疑问加站长微信联系(非本文作者)