callPut
This commit is contained in:
parent
73602b6c3d
commit
b432266486
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user