Example of POST vpz/input in PHP language¶
For the simulator ‘wwdm.vpz’ whose Id is 266, use the PHP code into a php tag :
- <?php
- … PHP code …
?>
Example illustrating :
‘compact’ as style of presentation,
‘json’ as format,
value ‘all’ as ‘parselect’ (to receive information of all the existing parameters and conditions)
value ‘all’ as ‘outselect’ (to receive information of all the existing output datas and views)
with ‘application/json’ as ‘Content-Type’
Memo
# PHP code : # send POST request and return response datas function send_post_and_receive($url, $inputdata) { # ob_start(); $c = curl_init(); # curl_setopt($c, CURLOPT_POST, TRUE); curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); # curl_setopt($c, CURLOPT_URL, $url); # # to follow redirect curl_setopt($c, CURLOPT_FOLLOWLOCATION, True); # $json_inputdata = json_encode($inputdata); curl_setopt($c, CURLOPT_POSTFIELDS, $json_inputdata); # curl_exec($c); $buffer_str = ob_get_contents(); ob_end_clean(); # $responsedata = json_decode($buffer_str, TRUE); curl_close($c); return $responsedata; }# PHP code : ####################### # request and response ####################### $inputdata = ["vpz"=>266, "mode"=>"compact", "format"=>"json"]; $inputdata['parselect'] = "all"; $inputdata['outselect'] = "all"; $responsedata = send_post_and_receive($url="http://erecord.toulouse.inra.fr:8000/vpz/input/", $inputdata=$inputdata); ########################################################## # responsedata in case of 'compact' style of presentation ########################################################## # duration in 'compact' style of presentation if (array_key_exists("duration", $responsedata)){ $duration_value = $responsedata['duration']; print ("duration value : ".$duration_value."<br />"); } # begin in 'compact' style of presentation if (array_key_exists('begin', $responsedata)){ $begin_value = $responsedata['begin']; print ("begin value : ".$begin_value."<br />"); } # parameters in 'compact' style of presentation if (array_key_exists('pars', $responsedata)){ $pars = $responsedata['pars']; print ("parameters (selection_name and value, condition name and parameter name) : <br />"); foreach ($pars as $par){ $par_selection_name = $par['selection_name']; $par_cname = $par['cname']; $par_pname = $par['pname']; $par_value = $par['value']; print ($par_selection_name." ".$par_value.", ".$par_cname." ".$par_pname."<br />"); } } # conditions identity in 'compact' style of presentation if (array_key_exists('conds', $responsedata)){ $conds = $responsedata['conds']; foreach ($conds as $cond_selection_name){ $cond_selection_name = $cond_selection_name['selection_name']; print ("condition selection_name : ".$cond_selection_name."<br />"); } } # views identity in 'compact' style of presentation if (array_key_exists('views', $responsedata)){ $views = $responsedata['views']; foreach ($views as $view_selection_name){ $view_selection_name = $view_selection_name['selection_name']; print ("view selection_name : ".$view_selection_name."<br />"); } } # output datas identity in 'compact' style of presentation if (array_key_exists('outs', $responsedata)){ $outs = $responsedata['outs']; foreach ($outs as $out_selection_name){ $out_selection_name = $out_selection_name['selection_name']; print ("output data selection_name : ".$out_selection_name."<br />"); } }