This language bar is your friend. Select your favorite languages!

Idiom #183 Make HTTP PUT request

Make a HTTP request with method PUT to 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)
fetch(u, {
        method: "PUT",
	body: JSON.stringify(data)
require ext-curl

$url = 'http://localhost/tester/log.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$fields = array("id" => 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
$response = curl_exec($ch);

echo $response;
with TFPHTTPClient.Create(nil) do
use HTTP::Tiny qw();
my $response = HTTP::Tiny->new->put($u, {content => $http_request_body});
import requests
content_type = 'text/plain'
headers = {'Content-Type': content_type}
data = {}

r = requests.put(u, headers=headers, data=data)
status_code, content = r.status_code, r.content
require 'net/http'
http =
response = http.send_request('PUT', path, body)

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

Related idioms