How To Use Curl Put Request With Php Example
Jul 24, 2021
Hi Guys,
In this example,I will learn you how to use curl put request with php.you can easy and simply use curl put request with 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.
PHP Curl PUT Request:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.nicesnippets.com/api/users/7",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'first_name' => 'Demo',
'last_name' => 'Test',
'email' => '[email protected]'
]),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
"x-api-key: whateveriyouneedinyourheader"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
It will help you..
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example