Skip to content

Instantly share code, notes, and snippets.

@3l3n01
Forked from slav123/doPut.go
Created October 9, 2018 20:43
Show Gist options
  • Save 3l3n01/509dd9bc866a85a8b60acc3b3f4763a1 to your computer and use it in GitHub Desktop.
Save 3l3n01/509dd9bc866a85a8b60acc3b3f4763a1 to your computer and use it in GitHub Desktop.
PUT request GO LANG
func doPut(url string) {
client := &http.Client{}
request, err := http.NewRequest("PUT", url, strings.NewReader("<golang>really</golang>"))
request.SetBasicAuth("admin", "admin")
request.ContentLength = 23
response, err := client.Do(request)
if err != nil {
log.Fatal(err)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println("The calculated length is:", len(string(contents)), "for the url:", url)
fmt.Println(" ", response.StatusCode)
hdr := response.Header
for key, value := range hdr {
fmt.Println(" ", key, ":", value)
}
fmt.Println(contents)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment