curl api using variable post/get method

HI every one there are lot of confusion about curl may be you understand easily …   

$url= “phone=$phone&leadid=$leadid”; //initialized other variable
$header = array(“Accept: application/json”);                        //optional for json format.
$ch = curl_init();                                                                           // initiate the curl connection.
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);    // pass the header information.
//curl_setopt($ch, CURLOPT_ENCODING, “gzip”);          // decode the values before sending.
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘GET’);// use only GET method.
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘POST’);// use only GET method.
curl_setopt($ch, CURLOPT_POST, 1); // use only POST method (here i am using POST).
//curl_setopt($ch, CURLOPT_GET, 1); // use only POST method.
curl_setopt($ch, CURLOPT_URL, “https://pai-xyz-origen-xyz.com/control/CurlCallResponse”);
curl_setopt($ch, CURLOPT_POSTFIELDS, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //optional if you want to get response  from curl (true or false)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // verification certification on server use as optional values (true or false)
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)’);
$simpleResponse = curl_exec($ch);
//$jsnResponse = json_decode(curl_exec($ch));
$curl_info = curl_getinfo($ch); // give the details information in initialize parameter with in curl
print_r($curl_info);                      // print the detials
print_r($simpleResponse);         //print the curl response this true or false
curl_close($ch);                             // closed the curl connection

Leave a Reply