I'm getting error: EOF
on console when I read the XML response body.
Below is my code.
resp, err := http.Post(url, "application/xml", payload)
if err != nil {
response.WriteErrorString(http.StatusInternalServerError, err.Error())
return
}
defer resp.Body.Close()
dec := xml.NewDecoder(resp.Body)
if debug == true {
body, err := ioutil.ReadAll(resp.Body)
fmt.Println("=========== Response ==================")
if err != nil {
fmt.Printf("error: %v", err)
return
}
fmt.Println(string(body))
fmt.Println("=========== Response Ends =============")
}
err = dec.Decode(respStruct)
I suspect ioutil.ReadAll
is not working as expected.
Is there a reason why it's throwing this error?