(1)
$data = array ( "name" => "Hagrid" , "age" => "36" ); |
02 |
$data_string =
json_encode( $data ); |
03 |
04 |
$ch =
curl_init( 'http://api.local/rest/users' ); |
05 |
curl_setopt( $ch ,
CURLOPT_CUSTOMREQUEST, "POST" ); |
06 |
curl_setopt( $ch ,
CURLOPT_POSTFIELDS, $data_string ); |
07 |
curl_setopt( $ch ,
CURLOPT_RETURNTRANSFER,true); |
08 |
curl_setopt( $ch ,
CURLOPT_HTTPHEADER, array ( |
09 |
'Content-Type:
application/json' , |
10 |
'Content-Length:
' . strlen ( $data_string )) |
11 |
); |
12 |
|
13 |
$result =
curl_exec( $ch ); |