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
Post a Comment