1
以下是我的預期REQ XML來形成使得XML在HTTP POST golang發送
<custom key="234234e324e4">
<document name="sample" location="http://example.com">
</document>
</custom>
,使這個XML我用下面的Go代碼
type Documentxml struct {
XMLName xml.Name `xml:"document"`
Name string `xml:"name,attr"`
Location string `xml:"location,attr"`
}
type DeleteXml struct {
XMLName xml.Name `xml:"custom"`
Key string `xml:"key,attr"`
Document Documentxml `xml:"document"`
}
和下面的代碼中插入值進去
var requestxml DeleteXml
requestxml.Key = "12321321"
requestxml.Document.Name = "sample"
requestxml.Document.Location = "www.//sample.com"
bytexml, err := xml.Marshal(&requestxml)
\t client := &http.Client{}
\t url := "http://localhost:8080/searchblox/api/rest/docdelete"
\t // build a new request, but not doing the POST yet
\t req, err := http.NewRequest("POST", url, bytes.NewBuffer(bytexml))
\t if err != nil {
\t \t fmt.Println(err)
\t }
req.Header.Add("Content-Type", "application/xml; charset=utf-8")
\t // now POST it
\t resp, err := client.Do(req)
\t if err != nil {
\t \t fmt.Println(err)
\t }
\t fmt.Println(resp)
但這裏要求形成並不像我想像的要形成 請求XML形成爲:{{} {12321321 {}樣品www.//sample.com}} 請建議什麼是這裏
腳麻
的一個問題是XMLName是Documentxml和DeleteXml空。因此,請填寫空的「{}」值。 –
應該提到什麼 –