Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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
我用/usr/bin/curl编写的代码可以工作,但用php curl编写的代码不工作。我哪里出错了?_Php_Curl_Php Curl - Fatal编程技术网

我用/usr/bin/curl编写的代码可以工作,但用php curl编写的代码不工作。我哪里出错了?

我用/usr/bin/curl编写的代码可以工作,但用php curl编写的代码不工作。我哪里出错了?,php,curl,php-curl,Php,Curl,Php Curl,我已经在我正在使用的终端上编写了以下两个代码脚本,我用php编写的代码不起作用,我得到了一个缺少参数的警报 Terminal: /usr/bin/curl -s -X POST "https://api.xxxxxxx.com/action.json?type=modifycontact&resellerno=3040267&resellerpwd=xxxxxxx&lang=tr&responsetype=json" -d "registrycode=813860

我已经在我正在使用的终端上编写了以下两个代码脚本,我用php编写的代码不起作用,我得到了一个缺少参数的警报

Terminal: /usr/bin/curl -s -X POST "https://api.xxxxxxx.com/action.json?type=modifycontact&resellerno=3040267&resellerpwd=xxxxxxx&lang=tr&responsetype=json" -d "registrycode=81386095&ownercontactid=81045261&admincontactid=81045261&billcontactid=81045261&techcontactid=81045261"

PHP: 
$url = "https://api.xxxxxxx.com/action.json?type=modifycontact&resellerno=3040267&resellerpwd=xxxxxxx&lang=tr&responsetype=json";
$value = "registrycode=81386095&ownercontactid=81045261&admincontactid=81045261&billcontactid=81045261&techcontactid=81045261";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt ($ch, CURLOPT_POST, 1);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $value);
        curl_setopt($ch, CURLOPT_HEADER, FALSE); 
        curl_setopt($ch, CURLOPT_NOBODY, FALSE); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
        curl_setopt($ch, CURLOPT_TIMEOUT, 3);
        //$son = array();
        $sonlu = curl_exec($ch);
        $son['sonuc'] = (isset($sonlu) AND !empty($sonlu)) ? $sonlu : json_encode($sunucuhata);
        $son['httpcode'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $son['error'] = curl_error($ch);
        $son['errorno'] = curl_errno($ch);
        curl_close($ch);
print_r($son);

Terminal response: {"status":"success","description":"OK"}

PHP response: Array
(
    [sonuc] => {"status":"error","description":"4553 missing parameter"}
    [httpcode] => 200
    [error] => 
    [errorno] => 0
)

错误消息不是来自curl,而是API响应。所以API需要一些东西

您可以检查是否有此API的文档,其中用更多详细信息解释了错误消息

我在terminal curl和php之间看到的唯一区别是:php默认情况下不设置用户代理头。您的请求中可能缺少此标题。我不知道你的卷发版本,但像这样的东西可以工作:

 curl_setopt($ch, CURLOPT_USERAGENT, 'curl/7.61.1');
更新:


httpcode=>200,您的curl正在正确执行。问题出在您的$son['sonuc']分配上,如果curl没有给您任何内容,您是在对不存在的内容进行json_编码吗?变量试着先打印$sonlu r以查看curl的检查结果。您的php代码看起来与终端版本相同。是否有解释错误消息“4553缺少参数”的API文档?protip,这会更漂亮:我按照Hanshenrik所说的做了,错误消息:registrycode required。如果没有文档,您可以询问API支持“4553缺少参数”是什么意思?实际上是为了准确模拟curl cli的useragent,使用
curl_setopt($ch,CURLOPT_USERAGENT,'curl/”(curl_version()[“version]”) curl_setopt($ch, CURLOPT_USERAGENT, 'curl/' . curl_version()['version']);