03-Apr-2023
.
Admin
Hi guys,
Today i will explained How To Send Post Request With Parameters using curl In PHP Example. This example is so easy to use in php.
This article to i am explained to the how to send post request in php with using parameters in php example. So i am use to the first name or last name request in this example.
So let's start to the example and follow to the my all step.
Example :
<?php
$url = 'https://api.nicesnippets.com/api/users';
$fields = array(
'first_name' => urlencode($_POST['first_name'])
'last_name' => urlencode($_POST['last_name']),
);
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);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
Now you can check your own.
I hope it can help you...
#PHP 8
#PHP