In my project, I have a byte slice from a request's response.
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Println("StatusCode为" + strconv.Itoa(resp.StatusCode))
return
}
respByte, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("fail to read response data")
return
}
This works, but if I want to get the response's body for io.Reader
, how do I convert? I tried the newreader/writer but wasn't successful.
io.Reader
? In that case resp.Body is already of that type. – Arjan[]byte
to anio.Reader
(and io.ReadSeeker) – ANisus*bytes.Reader
which implements theio.Reader
interface. – Arjan