【问题标题】:why curl_exec($url) return the empty string为什么 curl_exec($url) 返回空字符串
【发布时间】:2016-11-23 06:07:12
【问题描述】:

代码:

<?php
$url = "oooff.com";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
?>

为什么上面的代码显示一个空白页?

任何帮助将不胜感激。

【问题讨论】:

  • 那么file_get_contents呢?
  • 您的代码中没有file_get_contents。你的意思是curl
  • 尝试检查 curl 请求中的错误if (curl_error($ch)){ echo curl_error($ch); }
  • 欢迎堆栈溢出 :-) 请查看How to Ask 以及如何创建minimal reproducible example。这将有助于获得有用的答案。我将此问题标记为关闭。

标签: php curl


【解决方案1】:

你的 curl 代码工作正常,但 file_get_contents($url) 不行,如果你尝试它会工作

$url = "http://www.oooff.com";
echo file_get_contents($url);

不同之处在于http://www的使用,您可以在此处查看手册以获取正确的路径http://php.net/manual/en/function.file-get-contents.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 2011-05-08
    • 1970-01-01
    相关资源
    最近更新 更多