http://www.rlsnet.ru/tn_alf_letter_DF.htm - 我有这个网址,在浏览器中工作正常,但如果我使用此方式提出请求:
$url = 'http://www.rlsnet.ru/tn_alf_letter_DF.htm';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($ch);
print_r(curl_getinfo($ch));
exit;
我得到了这个结果:
Array ( [url] => http://www.rlsnet.ru/tn_alf_letter_DF.htm [content_type] => text/html; charset=windows-1251 [http_code] => 404 [header_size] => 214 [request_size] => 72 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 14.925294 [namelookup_time] => 5.401249 [connect_time] => 5.643545 [pretransfer_time] => 5.643608 [size_upload] => 0 [size_download] => 87314 [speed_download] => 5850 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => 0 [starttransfer_time] => 12.941717 [redirect_time] => 0 )
http_code是404,为什么会这样?
更新:
$url = 'http://www.rlsnet.ru/tn_alf_letter_DF.htm';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.rlsnet.ru');
$data = curl_exec($ch);
print_r(curl_getinfo($ch));
exit;
仍然得到404
答案 0 :(得分:1)
它适用于我的代码。
尝试curl_setopt($ch, CURLOPT_TIMEOUT, 0);
和curl_setopt($ch, CURLOPT_TIMEOUT, 0)
根据您从print_r
你的卷曲版本是什么?我的是7.22.0
答案 1 :(得分:0)
相同的代码给了我[http_code] => 200
您的卷曲装置可能存在问题。
尝试检查phpinfo()
启用cURL支持
cURL信息7.30.0
3岁
功能
AsynchDNS否
调试否
GSS-谈判否
IDN是
IPv6是
Largefile Yes
NTLM是
SPNEGO否
SSL是
SSPI否
krb4否
libz是
CharConv否
协议dict,file,ftp,ftps,gopher,http,https,imap,imaps,pop3,pop3s,rtsp,smtp,smtps,telnet,tftp
主持人x86_64-apple-darwin11.4.2
SSL版本OpenSSL / 1.0.1e
ZLib版本1.2.8
答案 2 :(得分:0)
尝试设置User-Agent和Referer:
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0');
curl_setopt($curl, CURLOPT_REFERER, 'http://www.rlsnet.ru');