- Не достучаться до сайта используя Curl. Ошибка 404 not found/
- curl_errno
- Parameters
- Return Values
- Changelog
- Examples
- See Also
- User Contributed Notes 10 notes
- curl_error
- Список параметров
- Возвращаемые значения
- Список изменений
- Примеры
- Смотрите также
- User Contributed Notes 4 notes
- Curl Returnin 404 Error
- cURL returns 404 while the page is found in browser
- Curl_exec returns 404 not found error whereas url is found in browser
- curl returns 404 on valid page
- cuRL returnin 404 error
- cURL return HTML error 404 instead of JSON when called within bash script requesting php API
- Resource Not Found 404 Error when making an API call from cURL
Не достучаться до сайта используя Curl. Ошибка 404 not found/
Пытаюсь авторизироваться в своем кабинете на сайте pulscen.ru
Но никак не могу получить данные, все время выдает 404 not found, перепробывал все заголовки какие посылает браузер. Не достучать даже до главной страницы сайта.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
$url = "http://www.pulscen.ru"; $useragent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"; $cURLHeaders = array( 'Host' => "www.pulscen.ru", 'User-Agent'=>$useragent, 'Accept'=>"*/*", 'Accept-Language'=>"ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3", 'Accept-Encoding'=>"gzip, deflate", 'X-NewRelic-ID'=>"VQUFVVRACQEEUlBS", 'X-Requested-With'=>"XMLHttpRequest", 'Referer'=>"http://www.pulscen.ru/", 'Connection'=>"keep-alive" ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $cURLHeaders); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $data = curl_exec($ch); curl_close($ch); print_r($data);
При открытии нового сайта часто открывается страница 404 Not Found
Добрый день! Браузеры при попытке открытия нового сайта через раз перенаправляют на страницу "404.
Ошибка: 404 Not Found
Собственно при нажатии на кнопку выдаёт ошибку HTTP/1.1 404 Not Found Где тут ошибка, помогите, с.
Ошибка 404 Not Found
При переходе на любой сайт, при почти загрузившейся странице, перенаправляет на страницу с поиском.
Ошибка 404 Not Found
Hi! Установил WordPress на vds. Все страницы кроме главной и админки показывают Not Found 404.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
$url = "http://pulscen.ru/"; $useragent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, $useragent); curl_setopt($ch, CURLOPT_REFERER, "http://pulscen.ru/"); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'X-NewRelic-ID'=>"VQUFVVRACQEEUlBS", 'X-Requested-With'=>"XMLHttpRequest" )); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $data = curl_exec($ch); curl_close($ch); print_r($data);
curl_errno
Returns the error number for the last cURL operation.
Parameters
A cURL handle returned by curl_init() .
Return Values
Returns the error number or 0 (zero) if no error occurred.
Changelog
Examples
Example #1 curl_errno() example
// Create a curl handle to a non-existing location
$ch = curl_init ( ‘http://404.php.net/’ );
?php
// Execute
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_exec ( $ch );
// Check if any error occurred
if( curl_errno ( $ch ))
echo ‘Curl error: ‘ . curl_error ( $ch );
>
// Close handle
curl_close ( $ch );
?>
See Also
User Contributed Notes 10 notes
if someone need more information about curl errors
$error_codes =array(
[ 1 ] => ‘CURLE_UNSUPPORTED_PROTOCOL’ ,
[ 2 ] => ‘CURLE_FAILED_INIT’ ,
[ 3 ] => ‘CURLE_URL_MALFORMAT’ ,
[ 4 ] => ‘CURLE_URL_MALFORMAT_USER’ ,
[ 5 ] => ‘CURLE_COULDNT_RESOLVE_PROXY’ ,
[ 6 ] => ‘CURLE_COULDNT_RESOLVE_HOST’ ,
[ 7 ] => ‘CURLE_COULDNT_CONNECT’ ,
[ 8 ] => ‘CURLE_FTP_WEIRD_SERVER_REPLY’ ,
[ 9 ] => ‘CURLE_REMOTE_ACCESS_DENIED’ ,
[ 11 ] => ‘CURLE_FTP_WEIRD_PASS_REPLY’ ,
[ 13 ] => ‘CURLE_FTP_WEIRD_PASV_REPLY’ ,
[ 14 ]=> ‘CURLE_FTP_WEIRD_227_FORMAT’ ,
[ 15 ] => ‘CURLE_FTP_CANT_GET_HOST’ ,
[ 17 ] => ‘CURLE_FTP_COULDNT_SET_TYPE’ ,
[ 18 ] => ‘CURLE_PARTIAL_FILE’ ,
[ 19 ] => ‘CURLE_FTP_COULDNT_RETR_FILE’ ,
[ 21 ] => ‘CURLE_QUOTE_ERROR’ ,
[ 22 ] => ‘CURLE_HTTP_RETURNED_ERROR’ ,
[ 23 ] => ‘CURLE_WRITE_ERROR’ ,
[ 25 ] => ‘CURLE_UPLOAD_FAILED’ ,
[ 26 ] => ‘CURLE_READ_ERROR’ ,
[ 27 ] => ‘CURLE_OUT_OF_MEMORY’ ,
[ 28 ] => ‘CURLE_OPERATION_TIMEDOUT’ ,
[ 30 ] => ‘CURLE_FTP_PORT_FAILED’ ,
[ 31 ] => ‘CURLE_FTP_COULDNT_USE_REST’ ,
[ 33 ] => ‘CURLE_RANGE_ERROR’ ,
[ 34 ] => ‘CURLE_HTTP_POST_ERROR’ ,
[ 35 ] => ‘CURLE_SSL_CONNECT_ERROR’ ,
[ 36 ] => ‘CURLE_BAD_DOWNLOAD_RESUME’ ,
[ 37 ] => ‘CURLE_FILE_COULDNT_READ_FILE’ ,
[ 38 ] => ‘CURLE_LDAP_CANNOT_BIND’ ,
[ 39 ] => ‘CURLE_LDAP_SEARCH_FAILED’ ,
[ 41 ] => ‘CURLE_FUNCTION_NOT_FOUND’ ,
[ 42 ] => ‘CURLE_ABORTED_BY_CALLBACK’ ,
[ 43 ] => ‘CURLE_BAD_FUNCTION_ARGUMENT’ ,
[ 45 ] => ‘CURLE_INTERFACE_FAILED’ ,
[ 47 ] => ‘CURLE_TOO_MANY_REDIRECTS’ ,
[ 48 ] => ‘CURLE_UNKNOWN_TELNET_OPTION’ ,
[ 49 ] => ‘CURLE_TELNET_OPTION_SYNTAX’ ,
[ 51 ] => ‘CURLE_PEER_FAILED_VERIFICATION’ ,
[ 52 ] => ‘CURLE_GOT_NOTHING’ ,
[ 53 ] => ‘CURLE_SSL_ENGINE_NOTFOUND’ ,
[ 54 ] => ‘CURLE_SSL_ENGINE_SETFAILED’ ,
[ 55 ] => ‘CURLE_SEND_ERROR’ ,
[ 56 ] => ‘CURLE_RECV_ERROR’ ,
[ 58 ] => ‘CURLE_SSL_CERTPROBLEM’ ,
[ 59 ] => ‘CURLE_SSL_CIPHER’ ,
[ 60 ] => ‘CURLE_SSL_CACERT’ ,
[ 61 ] => ‘CURLE_BAD_CONTENT_ENCODING’ ,
[ 62 ] => ‘CURLE_LDAP_INVALID_URL’ ,
[ 63 ] => ‘CURLE_FILESIZE_EXCEEDED’ ,
[ 64 ] => ‘CURLE_USE_SSL_FAILED’ ,
[ 65 ] => ‘CURLE_SEND_FAIL_REWIND’ ,
[ 66 ] => ‘CURLE_SSL_ENGINE_INITFAILED’ ,
[ 67 ] => ‘CURLE_LOGIN_DENIED’ ,
[ 68 ] => ‘CURLE_TFTP_NOTFOUND’ ,
[ 69 ] => ‘CURLE_TFTP_PERM’ ,
[ 70 ] => ‘CURLE_REMOTE_DISK_FULL’ ,
[ 71 ] => ‘CURLE_TFTP_ILLEGAL’ ,
[ 72 ] => ‘CURLE_TFTP_UNKNOWNID’ ,
[ 73 ] => ‘CURLE_REMOTE_FILE_EXISTS’ ,
[ 74 ] => ‘CURLE_TFTP_NOSUCHUSER’ ,
[ 75 ] => ‘CURLE_CONV_FAILED’ ,
[ 76 ] => ‘CURLE_CONV_REQD’ ,
[ 77 ] => ‘CURLE_SSL_CACERT_BADFILE’ ,
[ 78 ] => ‘CURLE_REMOTE_FILE_NOT_FOUND’ ,
[ 79 ] => ‘CURLE_SSH’ ,
[ 80 ] => ‘CURLE_SSL_SHUTDOWN_FAILED’ ,
[ 81 ] => ‘CURLE_AGAIN’ ,
[ 82 ] => ‘CURLE_SSL_CRL_BADFILE’ ,
[ 83 ] => ‘CURLE_SSL_ISSUER_ERROR’ ,
[ 84 ] => ‘CURLE_FTP_PRET_FAILED’ ,
[ 84 ] => ‘CURLE_FTP_PRET_FAILED’ ,
[ 85 ] => ‘CURLE_RTSP_CSEQ_ERROR’ ,
[ 86 ] => ‘CURLE_RTSP_SESSION_ERROR’ ,
[ 87 ] => ‘CURLE_FTP_BAD_FILE_LIST’ ,
[ 88 ] => ‘CURLE_CHUNK_FAILED’ );
curl_error
Возвращает понятное сообщение об ошибке для последней операции cURL.
Список параметров
Дескриптор cURL, полученный из curl_init() .
Возвращаемые значения
Возвращает сообщение об ошибке или » (пустую строку), если ошибки не произошло.
Список изменений
Примеры
Пример #1 Пример использования curl_error()
// Создаём дескриптор curl к несуществующему адресу
$ch = curl_init ( ‘http://404.php.net/’ );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
?php
if( curl_exec ( $ch ) === false )
echo ‘Ошибка curl: ‘ . curl_error ( $ch );
>
else
echo ‘Операция завершена без каких-либо ошибок’ ;
>
// Закрываем дескриптор
curl_close ( $ch );
?>
Смотрите также
User Contributed Notes 4 notes
If you want to fetch the error message, make sure you fetch it before you close the current cURL session or the error message will be reset to an empty string.
For a 404 response to actually trigger an error as the example seems to be trying to demonstrate the following option should be set:
CURLE_HTTP_RETURNED_ERROR (22)
This is returned if CURLOPT_FAILONERROR is set TRUE and the HTTP server returns an error code that is >= 400. (This error code was formerly known as CURLE_HTTP_NOT_FOUND.)
If you’re using curl_multi and there’s an error, curl_error() will remain empty until you’ve called curl_multi_info_read(). That function «pumps» the information inside the curl libraries to the point where curl_error() will return a useful string.
This should really be added to the documentation, because it’s not at all obvious.
curl_error is not a textual representation of curl_errno.
It’s an actual error *message*.
If you want textual representation of error *code*, look for curl_strerror.
- Функции cURL
- curl_close
- curl_copy_handle
- curl_errno
- curl_error
- curl_escape
- curl_exec
- curl_getinfo
- curl_init
- curl_multi_add_handle
- curl_multi_close
- curl_multi_errno
- curl_multi_exec
- curl_multi_getcontent
- curl_multi_info_read
- curl_multi_init
- curl_multi_remove_handle
- curl_multi_select
- curl_multi_setopt
- curl_multi_strerror
- curl_pause
- curl_reset
- curl_setopt_array
- curl_setopt
- curl_share_close
- curl_share_errno
- curl_share_init
- curl_share_setopt
- curl_share_strerror
- curl_strerror
- curl_unescape
- curl_upkeep
- curl_version
Curl Returnin 404 Error
cURL returns 404 while the page is found in browser
I quickly checked the said page with LiveHeaders enabled and I noticed bunch of cookies set. I suspect that, since it’s not «normal» url, you need to hand those cookies while being redirected otherwise you end being kicked out with 404. Use CURLOPT_COOKIEJAR with your cURL instance at start. See: http://php.net/manual/pl/function.curl-setopt.php
Curl_exec returns 404 not found error whereas url is found in browser
When you set the CURLOPT_NOBODY option to true , it means cURL will do a HEAD request instead of a GET request.
The URL seems to give a 200 on GET requests, but a 404 on HEAD requests.
Try setting CURLOPT_NOBODY to false .
curl returns 404 on valid page
The problem seems to come from you CURLOPT_NOBODY option.
I’ve tested your code both with and without this line and the http code returns 404 when CURLOPT_NOBODY is present, and 200 when it’s not.
The PHP manual informs us that setting the CURLOPT_NOBODY option will transform your request method to HEAD , my guess is that the server on which bostonglobe.com is hosted doesn’t support that method.
cuRL returnin 404 error
I can guess a few things that it can be checked from the server side, to show the error.
1) As it is stated in other answers, be sure to set all the necessary headers, you can check them e.g. by firebug, as it is shown in here,
or you can get the headers by php get_headers function.
to set it usecurl_setopt($ch, CURLOPT_HTTPHEADER, array("HeaderName: HeaderValue"));
2) When you open a page in the browser(excluding form submit with post method) it makes a get request, instead of post, so if in the server side it is checked $_GET, then your post request will not be considered.
3) If you sure that it should be a post request(say, it is a form submit), then the following can be a problem: some forms can have hidden fields, that again are being checked in the server, and if they are not set, error can be returned. So, you should look at the source code of the form and add them(if there are any) to your post parameters.
4) if you are submitting a form, be sure to set the submit button with its name and value as well, because similar to hidden fields, this can be checked as well.
5) Cookies can be a problem as well, because by default browser has it , and curl does not. To to able to set and read cookies use this code
// set cookie
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
// use cookie
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);here, $cookie_file path to the cookies file. Do not know in linux or mac, but in windows be sure to use absolute path to the cookie file.
6) Also, you can set the referer by
curl_setopt($ch, CURLOPT_REFERER, 'http://www.myaddress.com/mypage.php');
EDIT: In case of ajax request you might want to add a header X-Requested-With with value as XMLHttpRequest
cURL return HTML error 404 instead of JSON when called within bash script requesting php API
set -- "https://example.com/api/"$"-api.php"
You replace all the arguments list with only one argument (the URL).
Then argument $2 becomes empty as it calls curl :You don’t need to use set — with bash as it has arrays. It is not needed even for your usage since it does not deal with array data at all. Anyway, here is your code fixed while still using set —
#! /usr/bin/bash
if [ $# = 2 ]; then
set -- "https://example.com/api/"$"-api.php" "$2"
# t1=`date +%s`
curl -S -v -d "$2" "$1"
else
echo "you should specify only two arguments"
fiHere is equivalent code without using set — and making arguments immutable, witch is a better coding practice:
#! /usr/bin/bash
if [ $# = 2 ]; then
url="https://example.com/api/$1-api.php"
# t1=`date +%s`
data="$2"
curl -S -v -d "$data" "$url"
else
echo "you should specify only two arguments"
fiResource Not Found 404 Error when making an API call from cURL
kek just solved this very challenge.
Have you considered that the «Cyber Gang» (context of the challenge) may have changed the endpoint from balances to something else?
Considering that you get a 404 balance from curling get-balances, perhaps you could figure out a way to find other subdomains 🙂