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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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将无法工作_Php_Api_Curl_Dropbox_Dropbox Api - Fatal编程技术网

如果通过浏览器加载,Curl和php将无法工作

如果通过浏览器加载,Curl和php将无法工作,php,api,curl,dropbox,dropbox-api,Php,Api,Curl,Dropbox,Dropbox Api,我正在尝试将此调用的响应写入文件,但只有在cli中运行该响应时,它才会写入。当我通过浏览器运行它时,什么都没有发生。 $url = 'https://api.dropbox.com/1/oauth2/token'; $app_key = '************'; $app_secret = '***********'; $auth_code = '******************************'; $redirect_uri = "https://dev.subely.c

我正在尝试将此调用的响应写入文件,但只有在cli中运行该响应时,它才会写入。当我通过浏览器运行它时,什么都没有发生。
$url = 'https://api.dropbox.com/1/oauth2/token';

$app_key = '************';
$app_secret = '***********';

$auth_code = '******************************';
$redirect_uri = "https://dev.subely.com/test/";

$rdata = 'code=' . $auth_code . '&grant_type=authorization_code&redirect_uri=' . $redirect_uri;

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $rdata);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_USERPWD, $app_key.':'.$app_secret);


$response = curl_exec( $ch );

file_put_contents("/tmp/response.log", $response, FILE_APPEND);
echo "done";
?>

很可能是SSL验证问题(默认SSL验证为
TRUE
)。正如您所说,它在CLI中工作,但在web中不工作

此外,如果您检查curl执行,也会很好

$response = curl_exec( $ch );

if($response === false) {
    echo 'Curl error: ' . curl_error($ch);
} else {
   file_put_contents("/tmp/response.log", $response, FILE_APPEND);
}

检查
$response
是否有任何值未通过
变量转储($response)它没有。这只是一连串的回应,我并没有理解你们
它只是一个响应字符串
?@Anant如果我在cli中运行它,它会工作得很好。只是不从Web服务器可能是其SSL验证问题尝试添加此。curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);默认的SSL验证器是trueNice+1.
$response = curl_exec( $ch );

if($response === false) {
    echo 'Curl error: ' . curl_error($ch);
} else {
   file_put_contents("/tmp/response.log", $response, FILE_APPEND);
}