Send json in HTTP POST request by CURL php

A simple post operation by php curl. And send some json data.

//extract data from the post
extract($_POST);

//set POST variables
$url = 'http://aajit.com/apipath';
$jsodata='{"to":"foo", "msg":"bar", "token":"blah"}';
$fields_string ="aajgw=".$jsodata;
 
//open connection
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 1); // 1 for number of params (aajgw)
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);
echo $result;

//close connection
curl_close($ch);
  • Guest

    if your are from aajit.com Please send your skype or add me
    ” zahirwattoo ” have some project to work on it. waiting your help