0

以下代码有什么问题?

<?php
    function file_get_contents_curl($url) 
    {
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_URL, $url);

        $data = curl_exec($ch);
        curl_close($ch);

        return $data;
    }

    $var = file_get_contents_curl("http://www.sahibinden.com/131521670");
    var_dump($var);      

?>

它只显示 bool(false)

将http://www.sahbinden.com/131521670放在浏览器地址栏上时,URL 可能会出现问题,浏览器重定向到我想要其内容的另一个页面。

当我添加以下行时

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $fp );

输出是

* About to connect() to www.sahibinden.com port 80 (#0)
*   Trying 195.33.232.72... * connected
* Connected to www.sahibinden.com (195.33.232.72) port 80 (#0)
> GET /131521670 HTTP/1.1

Host: www.sahibinden.com

Accept: */*

* Closing connection #0
* Failure when receiving data from the peer

CURLOPT_HEADER, 1); 也产生相同的结果。

4

0 回答 0