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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -