我正在尝试解码HTML响应的XML内容。
=>我将响应正文保存为字符串变量,并成功使用xml.Unmarshal函数进行了解码。代码如下:
err = xml.Unmarshal([]byte(outs), &v)
if err != nil {
fmt.Printf("error is here: %v", err)
return
}
我认为问题不在于响应正文的实际内容。
现在是我的实际代码:
req1, err := http.NewRequest("GET", concat([]string{domain, defects_link}), nil)
error_handler(err)
req1.Close = true //I tried with and without this line
resp1, err := client.Do(req1)
error_handler(err)
fmt.Printf("\n %s \n", resp1.Status)
defer resp1.Body.Close()//I tried with and without this line
conts1, err := ioutil.ReadAll(resp1.Body)
error_handler(err)
fmt.Println("Response Body is Here :", string(conts1))//Contents are Printed Here
以上代码的最后一行打印响应。但是下面的代码会出现“错误:EOF”。
if err := xml.NewDecoder(resp1.Body).Decode(&v); err != nil {
fmt.Printf("error is : %v", err)
return
}
我的代码出了什么问题,请帮忙。