php curl返回包含内容的http_代码404,浏览器正常

php curl返回包含内容的http_代码404,浏览器正常,php,curl,Php,Curl,我想使用php/curl函数删除此页面以获取产品信息 但是,curl返回http_code=404,但浏览器是正常的。在类似的主题中,我在代码中设置了header、cookie和referer,仍然有http_代码404 该网页在Firefox下工作正常,但Firebug也显示404 这里有什么问题 <?php $cookie_file = './cookie.txt'; $url = "http://www.easymall.my/flower/item-636507.html";

我想使用php/curl函数删除此页面以获取产品信息

但是,curl返回http_code=
404
,但浏览器是正常的。在类似的主题中,我在代码中设置了header、cookie和referer,仍然有http_代码404

该网页在Firefox下工作正常,但Firebug也显示404

这里有什么问题

<?php
 $cookie_file = './cookie.txt';
 $url = "http://www.easymall.my/flower/item-636507.html";

 $ch = curl_init ( $url );
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
 curl_setopt($ch, CURLOPT_MAXREDIRS, 5);   
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

 $User_Agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906    Firefox/3.0';      
 $request_headers = array();
 $request_headers[] = 'User-Agent: '. $User_Agent;
 $request_headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
 curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
 curl_setopt ( $ch, CURLOPT_AUTOREFERER, true );     
 curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
 curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);

 curl_exec ( $ch );
 var_dump ( curl_getinfo ( $ch ) );
 if (curl_errno ( $ch )) {
  print curl_error ( $ch );
  } else {
  curl_close ( $ch );
  }
 ?>


array(22) { ["url"]=> string(46) "http://www.easymall.my/flower/item-636507.html" 
["content_type"]=> string(9) "text/html" ["http_code"]=> int(404) ["header_size"]=> 
int(279) ["request_size"]=> int(232) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) 
["redirect_count"]=> int(0) ["total_time"]=> float(0.188) ["namelookup_time"]=> float(0) ["connect_time"]=> float(0.016) ["pretransfer_time"]=> float(0.016) ["size_upload"]=> float(0) ["size_download"]=> float(17830) ["speed_download"]=> float(94840) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(0) ["starttransfer_time"]=> float(0.11) ["redirect_time"]=> float(0) ["certinfo"]=> array(0) { } ["redirect_url"]=> string(0) "" }

问题不是你的
curl
回答。这与网站有关。它正在发送一个
404
标题,如果您查看开发人员控制台网络选项卡,可以看到该标题


您正在抓取的站点()正在发送您的
404
。由他们来解决问题,不是你的代码造成的



网站配置错误。该网站正在通过
.htaccess
http\u response\u code(404)
甚至
header()发送404。在不知道代码库是什么样子的情况下,我无法确切地告诉您为什么它会给您一个
404
,但是如果它让您感到非常不舒服,您应该与他们联系并让他们知道。

显然服务器配置错误Hi Darren,来自Firebug,它同时发送404头和内容。为什么浏览器不显示404未找到错误?由于服务器配置错误,页面在所有浏览器?@Pheng KhaiTan下正常显示。该网站正在通过
.htaccess
http\u response\u code(404)
甚至
headeer()发送
404
。在不知道代码库是什么样子的情况下,我无法确切地告诉您为什么它会给您一个
404
GET item-636507.html  404 Not Found   easymall.my   17.4 KB   117.53.152.29:80

Cache-Control   no-store, no-cache, must-revalidate
Connection  Keep-Alive
Content-Type    text/html
Date    Wed, 06 Aug 2014 01:58:12 GMT
Keep-Alive  timeout=5, max=100
Server  Apache/2.4.7 (Unix) OpenSSL/1.0.1e PHP/5.5.6 mod_perl/2.0.8-dev Perl/v5.16.3
Transfer-Encoding   chunked
X-Powered-By    PHP/5.5.6
view source
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection  keep-alive
Cookie  __utma=86241292.2105711989.1407286316.1407286316.1407290031.2; __utmc=86241292; __utmz=86241292.1407286316.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=86241292.1.10.1407290031
Host    www.easymall.my
User-Agent  Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0