【问题标题】:php curl output ehco it self [duplicate]php curl输出ehco它自己[重复]
【发布时间】:2019-10-15 09:25:13
【问题描述】:

我编写了一个 php curl 函数,用于从启用 ssl 的站点下载网页。 它不像我想要的那样工作。即使我没有在其他地方使用 echo 命令,它也会自动回显。 我想用这个功能来保存下载页面,但它保存的是 1 个文件而不是全部数据。

我已经用谷歌搜索过这个问题,但没有成功。写堆栈溢出对我来说总是最后的选择,由于我的英语不好以及解释不好,我总是避免

function gssl($target_url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,true);
    curl_setopt($ch, CURLOPT_CAINFO, 'C:\Users\PC\Desktop\ssl\cacert-2019-05-15.pem');
    //curl_setopt($ch, CURLOPT_CAINFO, 'https://curl.haxx.se/ca/cacert-2019-05-15.pem');
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_URL,$target_url);
    curl_setopt($ch, CURLOPT_VERBOSE,true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 100);
    $html= curl_exec($ch);
    return $html;
    }

function write($post,$myFile){
$fh = fopen($myFile, 'a+') or die("can't open file");
fwrite($fh, $post);
fclose($fh);
}

【问题讨论】:

    标签: php curl


    【解决方案1】:

    将 CURLOPT_RETURNTRANSFER 设置为 true

    【讨论】:

      【解决方案2】:

      您返回的是curl_exec($ch); 的结果,而不是来自网站的页面。使用CURLOPT_FILE cURL 选项将返回的数据直接放入文件中。

      正如詹姆斯所说,也启用CURLOPT_RETURNTRANSFER。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-13
        • 1970-01-01
        • 1970-01-01
        • 2021-05-23
        • 2020-11-14
        相关资源
        最近更新 更多