Seach

how to create a http post request using curl in php

<?php
$url ='http://localhost/curl/data.php'; //data to be dumped
$data = array
(
'name'=>"xxx",
'age'=>'xxx',
'gender'=>'xxxxx',
'phone'=>'xxxxxxxxxxx'
);
$curl = curl_init(); //curl initalizing
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL =>$url,
    CURLOPT_POST => 1, //setting it to post request
    CURLOPT_POSTFIELDS =>$data
));//option array
$resp = curl_exec($curl); //curl executed
$error = curl_error($curl); //getting error
if(!$error)
{
print_r($resp);
}
curl_close($curl); //closing the curl
?>

post curl file