This commit is contained in:
mr 2024-10-16 13:50:09 +02:00
parent 73602b6c3d
commit b432266486

View File

@ -84,4 +84,20 @@ func (caller *HTTPCaller) CallPost(url string, subpath string, body map[string]i
return io.ReadAll(resp.Body)
}
// NO PUT IN HERE TO DANGEROUS TO USE ON A REMOTE SERVER, MAYBE NEEDED IN THE FUTURE
// CallPost calls the POST method on the HTTP server
func (caller *HTTPCaller) CallPut(url string, subpath string, body map[string]interface{}) ([]byte, error) {
postBody, _ := json.Marshal(body)
responseBody := bytes.NewBuffer(postBody)
req, err := http.NewRequest(http.MethodPut, url+subpath, responseBody)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return io.ReadAll(resp.Body)
}