dshu1235 2015-07-22 09:23
浏览 165

Golang:get.http(url)没有响应

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

  • 写回答

1条回答 默认 最新

  • dou8mwz5079 2015-07-22 09:39
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog