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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…