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);

aaJ TECH LOG

Md.Ashraful Abedein
  ©2010 www.ashraful.tk