Open nshalman opened 4 years ago
It seems that the correct way to encode the data is along the lines of (see https://stackoverflow.com/a/19253970) the following short snippet:
data := url.Values{}
data.Set("lshw", string(lshw))
data.Set("lldp", string(lldp))
data.Set("CHASSIS_TAG", "some-chassis-tag")
body := strings.NewReader(data.Encode())
req, err := http.NewRequest("POST", "http://collins:9000/api/asset/tumblrtag1", body)
Note the use of url.Values{}
and calling its Encode()
function.
The complete piece of code that worked, though crude and inexpertly written is this:
func intake() {
lshwFile, err := os.Open("/tmp/lshw.xml")
if err != nil {
log.Fatal(err)
}
defer lshwFile.Close()
lshw, err := ioutil.ReadAll(lshwFile)
lldpFile, err := os.Open("/tmp/lldp.xml")
if err != nil {
log.Fatal(err)
}
defer lldpFile.Close()
lldp, err := ioutil.ReadAll(lldpFile)
data := url.Values{}
data.Set("lshw", string(lshw))
data.Set("lldp", string(lldp))
data.Set("CHASSIS_TAG", "some-chassis-tag")
body := strings.NewReader(data.Encode())
req, err := http.NewRequest("POST", "http://collins:9000/api/asset/tumblrtag1", body)
if err != nil {
log.Fatal(err)
}
req.SetBasicAuth("blake","admin:first")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := http.DefaultClient.Do(req)
defer resp.Body.Close()
log.Printf("resp: %+v\n", resp)
respbody, err := ioutil.ReadAll(resp.Body)
log.Printf("resp body: %s\n", respbody)
if err != nil {
log.Printf("err: %+v\n", err)
}
}
Asset Updating should be sending data in the post body, not the request URI.
Assets.Update
usesaddOptions
whichThis seems to fail when trying to send in
Lshw
andLldp
information:When using curl with the same data files (per the API documentation for Collins) it works just fine:
Let me know if this issue needs further clarification.
Thank you for Collins, go-collins, and your attention.