Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将php url中的数据发布为json public function create\u plan\u paystack(){ $data=数组( “姓名”=>“每月聘用费”、“间隔”=>“每月”、“金额”=>500、'currency'=>“NGN'、'description'=>“测试” ); $sendjson=array(); $opts=数组( “http'=>数组( 'header'=>[“Authorization:Bearer”。$this->config->item('paystack_sk')。“\r\n”,“内容类型:application/json\r\n”], '方法'=>'获取', 'content'=>json\u encode($data)//http\u build\u query($data), ) ); 打印(可选); $context=stream\u context\u create($opts); $json=文件\u获取\u内容(“https://api.paystack.co/plan/“‘PLN_lp20ulqhzezihrc’,假,$context); $obj=json_decode($json); 印刷费($obj); }_Php_Json_Codeigniter - Fatal编程技术网

将php url中的数据发布为json public function create\u plan\u paystack(){ $data=数组( “姓名”=>“每月聘用费”、“间隔”=>“每月”、“金额”=>500、'currency'=>“NGN'、'description'=>“测试” ); $sendjson=array(); $opts=数组( “http'=>数组( 'header'=>[“Authorization:Bearer”。$this->config->item('paystack_sk')。“\r\n”,“内容类型:application/json\r\n”], '方法'=>'获取', 'content'=>json\u encode($data)//http\u build\u query($data), ) ); 打印(可选); $context=stream\u context\u create($opts); $json=文件\u获取\u内容(“https://api.paystack.co/plan/“‘PLN_lp20ulqhzezihrc’,假,$context); $obj=json_decode($json); 印刷费($obj); }

将php url中的数据发布为json public function create\u plan\u paystack(){ $data=数组( “姓名”=>“每月聘用费”、“间隔”=>“每月”、“金额”=>500、'currency'=>“NGN'、'description'=>“测试” ); $sendjson=array(); $opts=数组( “http'=>数组( 'header'=>[“Authorization:Bearer”。$this->config->item('paystack_sk')。“\r\n”,“内容类型:application/json\r\n”], '方法'=>'获取', 'content'=>json\u encode($data)//http\u build\u query($data), ) ); 打印(可选); $context=stream\u context\u create($opts); $json=文件\u获取\u内容(“https://api.paystack.co/plan/“‘PLN_lp20ulqhzezihrc’,假,$context); $obj=json_decode($json); 印刷费($obj); },php,json,codeigniter,Php,Json,Codeigniter,我想把$data数组作为json发布。 “这就是他们给我的方式。请帮帮我。使用curl $data = array("name" => "Hagrid", "age" => "36"); $data_string = json_encode($data);

我想把
$data
数组作为json发布。 “这就是他们给我的方式。请帮帮我。

使用curl

    $data = array("name" => "Hagrid", "age" => "36");                                                                    
    $data_string = json_encode($data);                                                                                   

    $ch = curl_init('http://api.local/rest/users');                                                                      
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($data_string))                                                                       
    );                                                                                                                   

    $result = curl_exec($ch);
或者你可以使用这两种方法中的任何一种


'method'=>'POST',我将方法更改为POST