【问题标题】:php CURL not working with dynamic URLsphp CURL 不适用于动态 URL
【发布时间】:2012-10-17 14:44:13
【问题描述】:

我不明白为什么 CURL 没有找到这个 URL。 CURL 引擎只是被带到一个 400 错误页面。

我的代码非常简单,并且非常适用于非动态 URL。

我希望它很容易被发现,例如缺少 CURL 选项。

我尝试过使用 $url = urlencode($url) 但这也没有用。

代码如下:

$url = 'http://www.destinations-uk.com/accommodations.php?link=accommodations&country=england&category=Reviews&id=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,            $url);
curl_setopt($ch, CURLOPT_HEADER,         true);
curl_setopt($ch, CURLOPT_NOBODY,         true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_TIMEOUT,        15);
$r = curl_exec($ch);
$r = explode("\n", $r);
$keys = array();
if(!empty($r)) $keys[] = array_shift($r);
foreach($r as $line){
    preg_match('/.+:\s/',$line,$match);
    if($match) $keys[substr($match[0],0,-2)] = preg_replace('/.+:\s/','', $line);
}
print_r($keys);

【问题讨论】:

    标签: php curl get dynamic-url


    【解决方案1】:

    也许,这是服务器端为了防止自动请求而做的事情。

    【讨论】:

    • 我认为您一定是对的 - 它适用于基于 google 的动态 URL。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-21
    • 2011-09-09
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多