";参数字典包含参数“”的空条目;php-api


"The parameters dictionary contains a null entry for parameter" php api

好吧,我刚开始使用API,有问题

这是一个工作代码的例子,它显示了网络的所有类别

function list_categories(){
    $c = curl_init(); 
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($c, CURLOPT_HTTPHEADER, $this->xmlHeader);

    curl_setopt($c, CURLOPT_URL, $this->apiUrl . "/api/Categories/Get"); 
    curl_setopt($c, CURLOPT_POSTFIELDS, null); 
    curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'GET'); 
    $contentResult = curl_exec($c); 
    curl_close($c); 
        echo $contentResult;    
}

这是我尝试使用单一产品的时候

function get_product($cod_prod){
            $c = curl_init(); 
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($c, CURLOPT_HTTPHEADER, $this->xmlHeader);
    curl_setopt($c, CURLOPT_URL, $this->apiUrl . "/api/Product/Get/$cod_prod"); 
    curl_setopt($c, CURLOPT_POSTFIELDS, null); 
    curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'GET'); 
    $contentResult = curl_exec($c);
    curl_close($c); 
    echo $contentResult;
}

用第二个代码我得到这个错误:

请求无效。参数字典包含"Secom.Net.WebApi.Controllers.ProductController"中方法"Secom.Net.WebApi.Models.ProductView Get(Int32)"的不可为null类型"System.Int32"的参数"Id"的null条目。可选参数必须是引用类型、可为null的类型,或声明为可选参数

所有有变量的函数都会给出相同的错误,所以我认为这有问题,它在函数外给出了相同的错误。。。

我不知道该怎么办…有人知道代码出了什么问题吗?


我试过

curl_setopt($c, CURLOPT_POST,true);
    curl_setopt($c, CURLOPT_POSTFIELDS, "Id=$Id");

但是"请求的资源不支持http方法'POST'"

对我来说,似乎你应该在请求中指定一个ID变量,通常是作为URL的一部分,但这并没有发生。

找到一种添加相关ID的方法,希望您不会再出现错误。

编辑:我想我在你的代码中发现了问题。你的名言放错地方了。

更改

curl_setopt($c, CURLOPT_URL, $this->apiUrl . "/api/Product/Get/$cod_prod");

curl_setopt($c, CURLOPT_URL, $this->apiUrl . "/api/Product/Get/" . $cod_prod);