doushenjia8514 2015-07-27 17:17
浏览 95
已采纳

使用http在Golang中读取FederationMetadata.xml

I am trying to get the FederationMetadata.xml using http in golan using the following way.

response, err := client.Get("https://domainc.local/FederationMetadata/2007-06/FederationMetadata.xml"). 

The response body comes back as all numeric values(see below) and not in XML format. But I am able to download this file from chrome as an xml file.

61 34 117 114 110 58 111 97 115 105 115 58 110 97 109 101 115 58
116 99 58 83 65 77 76 58 50 46 48 58 97 115 115 101 114 116 105 111
110 34 47 62 60 65 116 116 114 105 98 117 116 101 32 78 97 109 101
61 34 104 116 116 112 58 47 47 115 99 104 101 109 97 115 46 109
105 99 114 111 115 111 102 116 46 99 111 109 47 50 48 49 50 47 48
49 47 114 101 113 117 101 115 116 99 111 110 116 101 120 116 47 99 10

Code:

tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
client := &http.Client{Transport: tr}
response, err := client.Get("https://domainc.local/FederationMetadata/2007-06/FederationMetadata.xml")
if err != nil {
    os.Exit(1)
} else {
    defer response.Body.Close()
    fmt.Println(response.Body)
    responseXML, err := ioutil.ReadAll(response.Body)
    if err != nil {
        fmt.Printf("%s", err)
        os.Exit(1)
    }
    fmt.Println(responseXML)
}
  • 写回答

2条回答 默认 最新

  • duangou2046 2015-07-27 18:24
    关注

    responseXML is slice of bytes (a []byte).

    You must convert it to a string to print it, either with:

    fmt.Println(string(responseXML))
    

    or via %s in a Printf format string:

    fmt.Printf("This is the response: 
    %s
    ", responseXML)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败