go - Do I copy resp.Body? -


i learning go , have following code works fine:

resp, err := http.get(url)  // html    ... doc, err := html.parse(resp.body)  // parse html page 

now want print out html first parsing:

resp, err := http.get(url)    ... b, err := ioutil.readall(resp.body)  // line added, not working now... doc, err := html.parse(resp.body) 

i guess reason resp.body reader, can not call read twice? idea how can correctly? copy resp.body?

because client streams response body network, it's not possible read body twice.

read response []byte doing. create io.reader on bytes html parser using bytes.newreader.

resp, err := http.get(url) ... b, err := ioutil.readall(resp.body)   doc, err := html.parse(bytes.newreader(b)) 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -