Created
August 18, 2014 04:20
-
-
Save slav123/cbb3309052de5a870667 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
Just pass nil to the third argument: