17-Sep-2021
.
Admin
Hi guys,
Today i will explained How TO Set Or Extract Data From The Post Variable Using Curl. This example is so easy to use in php.
This Example Through I am explained How TO Set Or Extract Data From The Post Variable Using Curl request through. So let's start to the example.
<?php
$url = 'https://api.Nicesnippets.com/api/users';
$fields = array(
'first_name' => urlencode($_POST['last_name']),
'last_name' => urlencode($_POST['first_name'])
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
// Set HTTP Header for POST request
curl_setopt($crl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload))
);
//execute post
$result = curl_exec($ch);
curl_close($ch);
?>
Now you can check your own.
I hope it can help you...
#PHP 8
#PHP