curl适用于浏览器和osx cli,但不适用于phpstorm cli

时间:2015-07-01 16:06:11

标签: php curl phpstorm

我有一个非常奇怪的问题,不知道如何调试它。也许一些有经验的开发者可以帮助我我有以下代码:

$url = 'https://home.mobile.de/home/ses.html?customerId=471445&json=true&_='.time();
echo $url;
$agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36';

// Initiate curl
$ch = curl_init();
// Activate debugging
curl_setopt($ch, CURLOPT_VERBOSE, true);
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set browser user agent
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);

$php_object = json_decode($result);
var_dump($php_object);

我已将此代码放入名为playground.php的php文件中。如果我用Chrome打开playground.php(我使用MAMP作为本地服务器),那么一切都按预期工作。此外,如果我在osx命令行“php playground.php”上运行它按预期工作,但由于任何原因,如果我在Phpstorm cli中运行它,它将不起作用,如下所示。

enter image description here

知道可能出现什么问题以及如何调试此问题?

非常感谢提前。

1 个答案:

答案 0 :(得分:0)

感谢LazyOne,我发现防火墙规则阻止了传出请求。非常感谢!

相关问题