use curl to post data api php code example
Example 1: http post request php curl
$post = [
'teste' => $_POST['teste']
];
httpPost('url.com', $post);
function httpPost($url, $data)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
Example 2: create curl api request php with para
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "api.example.com");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);