duanjiao8007 2012-10-17 14:44 采纳率: 100%
浏览 121
已采纳

php CURL无法使用动态URL

I can't work out why this URL is not being found by CURL. The CURL engine is simply taken to a 400 error page.

My code is very simple and works fantastically with non-dynamic URLs.

I am hoping it's something easy to spot, for example, a missing CURL option.

I have tried using $url = urlencode($url) but that didn't work either.

Here's the code:

$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("
", $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);
  • 写回答

1条回答 默认 最新

  • dsg24156 2012-10-17 14:49
    关注

    Perhaps, this is something on the server-side done to prevent automated requests.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义