Php 返回“未设置参数”的REST调用
我正在尝试使用curl对API进行rest调用。这是我当前的代码:Php 返回“未设置参数”的REST调用,php,web-services,rest,curl,Php,Web Services,Rest,Curl,我正在尝试使用curl对API进行rest调用。这是我当前的代码: $service_url = '...'; $curl = curl_init($service_url); $curl_post_data = array( 'nome' => $this->name, 'email' => $this->email, 'age' => $this->age )
$service_url = '...';
$curl = curl_init($service_url);
$curl_post_data = array(
'nome' => $this->name,
'email' => $this->email,
'age' => $this->age
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
var_dump( $curl_response );
我知道包含姓名、电子邮件和年龄的数组包含信息,因为我重复了这些信息
问题是,当我var_转储$curl响应时,会收到以下消息:
{"status":"NOK","errorCode":-1,"errorMessage":"No Parameters sent"}
有什么想法吗?试试这个:
$service_url = '...';
$curl = curl_init($service_url);
$curl_post_data = array(
'nome' => $this->name,
'email' => $this->email,
'age' => $this->age
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS,http_build_query($curl_post_data)); // using http_query_builder
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // for receiving response from server
$curl_response = curl_exec($curl);
var_dump( $curl_response );
选项CURLOPT_RETURNTRANSFER将允许curl_exec将响应返回到可选的进一步解析