Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C#

Idiom #183 Make HTTP PUT request

Make a HTTP request with method PUT to the URL u

using System.Net.Http;
new HttpClient().PutAsync(u, content);
import "net/http"
req, err := http.NewRequest("PUT", u, body)
if err != nil {
	return err
}
req.Header.Set("Content-Type", contentType)
req.ContentLength = contentLength
response, err := http.DefaultClient.Do(req)

This assumes you know contentLength beforehand.
body is a io.Reader which can be nil.

New implementation...
< >
programming-idioms.org