复制一个html.Response,然后获取字符串

I have made an Url type that should contain the response body.

type Url struct {
    Address string
    Refresh string
    Watch   string
    Found   bool
    Body    bytes.Buffer // bytes.Buffer needs no initialization
}

An Url object is created with the right Address, and then I do

resp, err := http.Get(url.Address)

Now I would like to do something like the following, but I cannot get out of it:

io.Copy(url.Body, b) // Copy that to the Url buffer

As for now, the Url.Body field can be modified to another type if needed.

Afterwards, I want to get the string from that Buffer/Writer/whatever, but I assume this will be easy as soon as I will manage the former copy.

Regards, Le Barde.

I guess you want to use ioutil.ReadAll which returns []byte:

resp, err := http.Get(url.Address)
if err != nil {
   // handle error
}
defer resp.Body.Close()
url.Body, err = ioutil.ReadAll(resp.Body)