how to send a post request php code example
Example 1: php send put request
<?php
$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;
Example 2: post request php
$response = httpPost("http://mywebsite.com/update.php",
array("first_name"=>"Bob","last_name"=>"Dillon")
);
function httpPost($url, $data){
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}