php - Using Curl in CodeIgniter : How to send data using post method -


not going succeed when trying send data using post method. never used before.

this code of executing curl:

$url = license_url."validate_system_key/validate_key/";         //url-ify data post         $data['system_key']='a8z0-x1n7-s1v2-y1i5';         $data['domain']='http://example.com';             $fields_string = '';             foreach($data $key=>$value) { $fields_string .= $key.'='.$value.'&'; }             $fields_string = rtrim($fields_string,'&');               //open connection             $ch = curl_init();              //set url, number of post vars, post data             curl_setopt($ch,curlopt_url,$url);             curl_setopt($ch,curlopt_post,count($data));             curl_setopt($ch,curlopt_postfields,$fields_string);              curl_setopt($ch,curlopt_connecttimeout,10); # timeout after 10 seconds, can increase            //curl_setopt($ch,curlopt_header,false);             curl_setopt ($ch, curlopt_returntransfer, 1);  # set curl return data instead of printing browser.              curl_setopt($ch, curlopt_ssl_verifypeer, false);              //execute post             $result = curl_exec($ch);              //close connection             curl_close($ch);           $result=json_decode($result,true); 

and code on client url:

public function validate_key(){         $system_key=$_post['system_key'];         $domain=$_post['domain'];         $result['error']=3;         echo json_encode($result); } 

note: when not using post method (sending data through url) evrything fine. post method, not getting mistake! kind of appreciated! thanks.

use array instead of string in data passed string below:

foreach($data $key=>$value) {   $data[$key] = $value; } curl_setopt($ch,curlopt_postfields,$data); 

i hope work.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -