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 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数