function processCurlJsonrequest($URL, $fieldString)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_URL, $URL);
// curl_setopt($ch, CURLOPT_USERAGENT, $this->_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
// curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_cookie_file_path);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_cookie_file_path);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fieldString));
curl_setopt($ch, CURLOPT_POST, 1);
$resulta = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
return $resulta;
}
$data_string = array("title" => "jdsdfds","url"=>"sdfdfd","date"=>"2014-01-30");
processCurlJsonrequest('http://localhost/articles',$data_string);
Hi, I am using REST api post method, type JSON to post data by using curl function. But its not working at all and no output is showing.
I did test this by using Fiefox plugin RESTClient. its works fine, able to post data into my database. I am stuck when using PHP curl method to post data. Above is one of the example i took from internet but still not working. Need advice from senior.