golang Http ioutil.ReadAll 惊现 Unexpected EOF解决办法

今天用Golang 读取Get请求接口在走到 ioutil.ReadAll 碰到 Unexpected EOF,原代码如下

    url := ""

    client := &http.Client{}

    req, err := http.NewRequest("GET", url, nil)
    req.Close = true

    resp, err := client.Do(req)
    if err != nil {
        fmt.Println(`aaaaaa`)
        return nil, (err)
    }

    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println(`bbbbbb`)
        return ms, err
    }

当然,还是Google,最后发现返回是gzip压缩过的,而直接获取是获取不到的,所以要加设置要求接口明码返回

req.Header.Add("Accept-Encoding", "identity")

注:资料来源https://stackoverflow.com/questions/21147562/unexpected-eof-using-go-http-client

It looks like the that server (Apache 1.3, wow!) is serving up a truncated gzip response. If you explicitly request the identity encoding (preventing the Go transport from adding gzip itself), you won’t get the ErrUnexpectedEOF:

这句话是这么理解的吧?