http://www.rlsnet.ru/tn_alf_letter_DF.htm - I have this url, in the browser it works fine, but If I make a request using this:
$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;
I get this result:
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 )
the http_code is 404, why this happens?
UPDATED:
$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;
still getting 404
It works for me with your code.
Try curl_setopt($ch, CURLOPT_TIMEOUT, 0);
and curl_setopt($ch, CURLOPT_TIMEOUT, 0)
it could be a problem of timeout based on the connection time you posted from print_r
What's your curl version? mine is 7.22.0
Same code gives me [http_code] => 200
Maybe there's a problem in your curl installation.
Try to check your phpinfo()
cURL support enabled
cURL Information 7.30.0
Age 3
Features
AsynchDNS No
Debug No
GSS-Negotiate No
IDN Yes
IPv6 Yes
Largefile Yes
NTLM Yes
SPNEGO No
SSL Yes
SSPI No
krb4 No
libz Yes
CharConv No
Protocols dict, file, ftp, ftps, gopher, http, https, imap, imaps, pop3, pop3s, rtsp, smtp, smtps, telnet, tftp
Host x86_64-apple-darwin11.4.2
SSL Version OpenSSL/1.0.1e
ZLib Version 1.2.8
Try to set User-Agent and 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');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.