PHP Curl PUT Request Example Code
In this example, you will learn php curl put request example. Iām going to show you about put method in curl php. you'll learn php curl put request with body. i explained simply step by step how to call put request with data using php curl.
i will give you two very simple example here, one simple put request with php curl. so let's see bellow examples:
PHP Curl PUT Request:
<?php
$url = "https://reqres.in/api/users/2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$updateArray = ['name' => 'Hardik', 'email' => 'hardik@gmail.com'];
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($updateArray));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [];
$headers[] = 'Content-Type:application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$result = json_decode($result);
curl_close($ch);
print_r($result);
?>
i hope it can help you...