オンラインで入手できるXMLファイルにアクセスしようとしていますが、GET後にXML形式が消えます。
私が間違って何をしているのですか?
ありがとうございました!Golang HTTP XML解析の問題
func getHttp(address string) string{
resp, err := http.Get(address)
resp.Header.Add("Content-Type","application/xml; charset=utf-8")
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return (string(data))
}
新しいフォーマットは次のようになります。
{"SessionKey":"229eaeaa9fb14a0d85ff38ae4e0c7870_ecilpojl_018FC93424D13ECC0908CE5BC5E3F86B","Query":{"Country":"GB","Currency":"GBP","Locale":"en-gb","Adults":1,"Children":0,"Infants":0,"OutboundDate":"2016-10-08","LocationSchema":"Default","CabinClass":"Economy","GroupPricing":false},
代わりの
<SessionKey>229eaeaa9fb14a0d85ff38ae4e0c7870_ecilpojl_018FC93424D13ECC0908CE5BC5E3F86B</SessionKey>
<Query>
<Country>GB</Country>
<Currency>GBP</Currency>
<Locale>en-gb</Locale>
<Adults>1</Adults>
<Children>0</Children>
<Infants>0</Infants>
<OutboundDate>2016-10-08</OutboundDate>
<LocationSchema>Default</LocationSchema>
<CabinClass>Economy</CabinClass>
<GroupPricing>false</GroupPricing>
</Query>
問題はあなたのメインです。主な関数を表示する:http://stackoverflow.com/help/mcveあなたは 'resp.Header.Add(" Content-Type "、" application/xml; charset = utf-8 ")' –
私のメインでは、この機能をウェブアドレス – donfrigo
と呼んでいますので、XMLではなくJSONです –