file_get_contents返回“找不到文件”

时间:2019-03-29 16:13:15

标签: php curl php-curl

我正在尝试获取url的内容,但是file_get_contents返回“找不到文件”。这是我正在使用的代码:

$url = "https://www.auction.com/residential/CA/active_lt/land_pt/resi_sort_v2_st/y_nbs/";
$context = stream_context_create(array(
    'https' => array(
        'method' => "GET",
        'header' =>
            "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" .
            "Accept-Language: en-US,en;q=0.8\r\n".
            "Keep-Alive: timeout=3, max=10\r\n",
            "Connection: keep-alive",
        'user_agent' => "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.66 Safari/535.11",
        "ignore_errors" => true,
        "timeout" => 3
    )
));
file_get_contents($url, false, $context);

但是它不起作用。你能帮忙做这个工作吗?或者,还有其他方法吗?

1 个答案:

答案 0 :(得分:0)

尽我所能尝试一下

$ch = curl_init();
$curlConfig = array(
    CURLOPT_URL            => "https://www.auction.com/residential/CA/active_lt/land_pt/resi_sort_v2_st/y_nbs/",
    //CURLOPT_HTTPHEADER     => array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n','Accept-Language: en-US,en;q=0.8\r\n','Keep-Alive: timeout=3, max=10\r\n','Connection: keep-alive'),
    CURLOPT_POST           => false,
    CURLOPT_RETURNTRANSFER => true,

);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
echo'<pre>';print_r($result);