My server is a Asp Net Web Api application. It works fine but now I try to call some services from PHP.
The .Net code is:
public void Post(int id, [FromBody] string param1)
In PHP side, I use:
$data = array("param1" => "value1");
$data_string = json_encode($data);
$ch = curl_init('http://localhost:53816/api/enterpriseapi/5');
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);
Using the Debug, the .Net service is effectively called from PHP, id is assigned to 5, but the POST "paramater1" parameter is always null, not "value1".
What am I doing wrong?
param1notparamater1, and it should be{"param1": "value1"}notvalue1.