http://plg1.yumenetworks.com/dynamic_preroll_playlist.vast2xml?domain=2210cZDclAme
when I call the link above from the server using http.Get
I get this response, an empty XML:
<?xml version="1.0" encoding="UTF-8"?>
<VAST version="2.0">
</VAST>
But when I call it from the browser it responsed with a valid XML,also when I called the link from a local server it works.
func getXmlVast(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()
// read xml http response
xmlData, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(xmlData), nil
}
Does anyone have an idea.
Thank you in advance
I think you get an empty response because you haven't specified the response headers type. Try to add:
resp, err := http.Get(url)
resp.Header.Add("Accept", "application/xml")
resp.Header.Add("Content-Type","application/xml; charset=utf-8")
if err != nil {
return "", err
}
Maybe this will solve your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.