Parse PHP and use curl to submit json data. The copy code is as follows: $ dataarray (nameHagrid, age36); $ data_stringjson_encode ($ data); $ chcurl_init (api. localrestusers); curl_setopt ($ ch, CURLO
The code is as follows:
$ 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 );
The http://www.bkjia.com/PHPjc/327922.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327922.htmlTechArticle code is as follows: $ data = array ("name" = "Hagrid", "age" = "36"); $ data_string = json_encode ($ data ); $ ch = curl_init ('http: // api. local/rest/users '); curl_setopt ($ ch, CURLO...