繁体   English   中英

php curl在给定的php服务器上不适用于给定的url

[英]php curl does not work for a given url on a given php server

我按如下方式使用PHP下载了一个页面,并且该页面有效(在我的开发计算机和我们的生产PHP服务器中):

$url = "http://google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec($ch);
curl_close($ch);
echo strlen($content);

但是,对于URL“ https://invue.com/patents/ ”,它只能在我的开发计算机上工作,而不能在生产PHP服务器上工作( strlen($content)返回0 )。

对可能是什么问题或如何找出问题有任何想法吗?

对于卷曲失败,可以使用函数curl_error

$url = "http://google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec($ch);
// check, Did something go wrong !?
if($content === false){ 
  // This will show what's wrong.
  echo 'Curl error: ' . curl_error($ch); 
}
curl_close($ch);
echo strlen($content);

有关更多信息,curl_error

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM