-
-
Save 3l3n01/509dd9bc866a85a8b60acc3b3f4763a1 to your computer and use it in GitHub Desktop.
PUT request GO LANG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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