Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
如何将终端cURL转换为PHP cURL?_Php_Json_Curl - Fatal编程技术网

如何将终端cURL转换为PHP cURL?

如何将终端cURL转换为PHP cURL?,php,json,curl,Php,Json,Curl,我在终端中使用curl来访问和请求JSON文件。它应该用一个JSON文件响应 curl --basic --user email : password "http:/www.appannie.com/v1/accounts/acntnum/..." 它在PHP curl中的等价物是什么 我使用了: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURL

我在终端中使用curl来访问和请求JSON文件。它应该用一个JSON文件响应

curl --basic --user email : password "http:/www.appannie.com/v1/accounts/acntnum/..."
它在PHP curl中的等价物是什么

我使用了:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, $email.".".$password);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    curl_close($ch);
     
    return $response;
但它失败了

我的参考资料如下:

我认为用户密码需要用“:”分隔

 curl_setopt($ch, CURLOPT_USERPWD, $email.":".$password);

不知怎的,我看不出确切的错误。但当我使用var_dump($response)时,它会打印bool(false)。这就是我认为卷曲失败的原因。我不知道为什么我的浏览器没有显示错误。我有另一个指向我的问题的链接,该链接是我在此之前创建的: