Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 返回“未设置参数”的REST调用_Php_Web Services_Rest_Curl - Fatal编程技术网

Php 返回“未设置参数”的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 )

我正在尝试使用curl对API进行rest调用。这是我当前的代码:

$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将响应返回到可选的进一步解析