Php 卷曲返回404错误

Php 卷曲返回404错误,php,parsing,curl,file-get-contents,Php,Parsing,Curl,File Get Contents,在尝试提取页面源代码时,我从一些URL中得到一个奇怪的错误。。一些URL返回的网页不存在时,它显然是 这是我正在使用的代码: 更新:添加了curl\u setopt($ch,CURLOPT\u FOLLOWLOCATION,1) 还是有同样的错误吗 function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RET

在尝试提取页面源代码时,我从一些URL中得到一个奇怪的错误。。一些URL返回的网页不存在时,它显然是

这是我正在使用的代码:

更新:添加了
curl\u setopt($ch,CURLOPT\u FOLLOWLOCATION,1)

还是有同样的错误吗

function file_get_contents_curl($url) {
$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

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

return $data;
}

$url = 'http://www.asos.com/American-Apparel/American-Apparel-Slim-Slack-Jeans/Prod/pgeproduct.aspx?iid=2503251&cid=4208&sh=0&pge=0&pgesize=20&sort=-1&clr=Truffle';

$html = file_get_contents_curl($url);

 echo $html;
有人知道原因吗?还是绕道而行?文件内容也不起作用,所以我猜是相同的错误

function file_get_contents_curl($url) {
$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

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

return $data;
}

$url = 'http://www.asos.com/American-Apparel/American-Apparel-Slim-Slack-Jeans/Prod/pgeproduct.aspx?iid=2503251&cid=4208&sh=0&pge=0&pgesize=20&sort=-1&clr=Truffle';

$html = file_get_contents_curl($url);

 echo $html;
变量转储(curl_getinfo($ch));产生


array(22){[“url”]=>string(67)”http://www.asos.com/holding.html#500?aspxerrorpath=/pgeproduct.aspx“[“内容类型”]=>string(9)“文本/html”[“http代码”]=>int(200)[“标题大小”]=>int(2131)[“请求大小”]=>int(437)[“文件时间”]=>int(-1)[“ssl验证结果”]=>int(0)[“重定向计数”]=>int(2)[“总时间”=>float(0.115457)[“名称查找时间”]=>float(4.1E-5)[“连接时间”]=>float(4.1E-5)[“传输前时间”]=>float(7.0E-5)[“大小上传”]=>float(0)[“大小下载”]=>float(4064)[“速度下载”]=>float(35199)[“速度上传”]=>float(0)[“下载内容长度”]=>float(4064)][“redirect\u time”]=>float(0.067962)[“certinfo”]=>array(0){}[“redirect\u url”]=>string(0)”}

已修复,至少我希望如此:

添加了
curl\u setopt($ch,CURLOPT\u USERAGENT,“Mozilla/4.0(兼容;MSIE 5.01;Windows NT 5.0)”);
现在一切似乎都正常了


非常感谢我收到的帮助。

试试
curl\u setopt($ch,curloopt\u FOLLOWLOCATION,true);
。也许asos.com会根据用户的不同阻止请求-Agent@PeterSzymkowski-谢谢-现在只返回一个空白页请显示
var\u dump(curl\u info($ch))
curl\u exec后的结果
@PeterSzymkowski用代码更新了问题,我现在正在尝试,但仍然得到相同的错误。请向我显示
curl\u info($ch)的输出
Ah,很好!当我检查curl作为用户代理发送的内容时,它与此非常相似。我看不出我在任何地方设置了它,但我不能排除某些安装程序在某个地方更改了该配置(或者它只是默认配置的那样)