1
を送信することは、私は、次の行くコードは、XMLは、次のHTTP POST golangに
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"`
}
と値を挿入するために、次のコードを使用しているこのXMLを作るために
<custom key="234234e324e4">
<document name="sample" location="http://example.com">
</document>
</custom>
を形成するために私の予想されるREQのxmlですそれ
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で空です。空の '{}'値のためです。 –
代わりに何を言及すべきか –