I just upgraded PHP from 7.2 to 7.4, but I noticed that PHP cURL Proxy is not working in 7.4.
Here is the code I am using:
<?php
$Socks5Proxy = 'socks5://127.0.0.7:1080'; //example proxy
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $Socks5Proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$data = curl_exec($ch);
curl_close($ch);
?>
Good afternoon,
I would like to get the data FROM this website using the API, and especially ids part ( aim ) in PHP but I obtain the following error : HTTP 415 Unsupported Media Type.
The code that I'm currently using is ( Иван Ясинский ) :
function getContentCurl($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64;
rv:25.0) Gecko/20100101 Firefox/25.0');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
return $result = curl_exec($ch);
}
$url = "https://cadres.apec.fr/cms/webservices/rechercheOffre/ids";
$content = getContentCurl($url);
var_dump($content);
Does anyone have any idea to overcome this issue ? Thank for your help.
Your missing the post data. I'm not sure of your exact query but an example query is in this code:
<?php
function getContentCurl($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"activeFiltre":true,"motsCles":"","fonctions":[],"lieux":[],"pointGeolocDeReference":{},"secteursActivite":[],"typesContrat":[],"typesConvention":[],"niveauxExperience":[],"sorts":[{"type":"DATE","direction":"DESCENDING"}],"pagination":{"startIndex":0,"range":20},"typeClient":"CADRE"}');
return $result = curl_exec($ch);
}
$url = "https://cadres.apec.fr/cms/webservices/rechercheOffre/ids";
$content = getContentCurl($url);
var_dump($content);
Outputs:
string(4083) "{"totalCount":78073,"offreFilters":[{"offreFiltering":"CONTRACT_TYPE_FILTERING","offreFilterItems":[{"key":101888,"count":69550},{"key":20053,"count":120},{"key":101930,"count":2144},{"key":101887,"count":6259}]},{"offreFiltering":"CONTRACT_DURATION_FILTERING","offreFilterItems":[{"key":143691,"count":4981},{"key":143692,"count":2562},{"key":143693,"count":976}]},{"offreFiltering":"COMPANY_TYPE_FILTERING","offreFilterItems":[{"key":143684,"count":35345},{"key":143685,"count":18112},{"key":143686,"count":13180},{"key":143687,"count":11436}]},{"offreFiltering":"POSITION_STATUS_FILTERING","offreFilterItems":[{"key":143688,"count":65264},{"key":143689,"count":1629},{"key":143690,"count":11180}]},{"offreFiltering":"EXPERIENCE_FILTERING","offreFilterItems":[{"key":101881,"count":36267},{"key":20043,"count":45182},{"key":20044,"count":11797},{"key":20045,"count":11317}]},{"offreFiltering":"GEOLOCALISABLE_FILTERING","offreFilterItems":[{"key":0,"count":6088},{"key":1,"count":71985}]},{"offreFiltering":"JOB_CODE_FILTERING","offreFilterItems":[{"key":101829,"count":1360},{"key":101828,"count":19240},{"key":101831,"count":11451},{"key":101830,"count":1336},{"key":101833,"count":17141},{"key":101832,"count":10470},{"key":101835,"count":4190},{"key":101834,"count":7131},{"key":101837,"count":11231},{"key":101836,"count":1463}]},{"offreFiltering":"LOCATION_FILTERING","offreFilterItems":[{"key":102099,"count":731},{"key":99700,"count":411},{"key":799,"count":77342}]},{"offreFiltering":"NAF_CODE_FILTERING","offreFilterItems":[{"key":101761,"count":1083},{"key":101760,"count":3773},{"key":101763,"count":3607},{"key":101762,"count":11726},{"key":101765,"count":385},{"key":101764,"count":2123},{"key":101767,"count":1134},{"key":101766,"count":1757},{"key":101769,"count":621},{"key":101768,"count":169},{"key":101771,"count":332},{"key":101770,"count":1241},{"key":101773,"count":9665},{"key":101772,"count":9572},{"key":101775,"count":695},{"key":101774,"count":2410},{"key":101777,"count":1597},{"key":101776,"count":1292},{"key":101779,"count":1308},{"key":101778,"count":336},{"key":101780,"count":158},{"key":101753,"count":11418},{"key":101752,"count":1529},{"key":101755,"count":1026},{"key":101754,"count":2418},{"key":101757,"count":4055},{"key":101756,"count":1413},{"key":101759,"count":959},{"key":101758,"count":271}]},{"offreFiltering":"NIVEAU_ETUDE"},{"offreFiltering":"DUREE_STAGE","offreFilterItems":[{"key":599765,"count":381},{"key":599766,"count":233},{"key":599767,"count":710},{"key":599768,"count":441},{"key":599769,"count":280},{"key":599770,"count":2936},{"key":599771,"count":3538}]},{"offreFiltering":"DATE_PRISE_POSTE","offreFilterItems":[{"key":599777,"count":75435},{"key":599778,"count":2209},{"key":599779,"count":429}]},{"offreFiltering":"PERIOD_FILTERING","offreFilterItems":[{"key":101850,"count":11054},{"key":101851,"count":32259},{"key":101852,"count":78073},{"key":101853,"count":78073}]},{"offreFiltering":"WAGE_FILTERING","offreFilterItems":[{"key":597179,"count":7147},{"key":599738,"count":38996},{"key":101840,"count":56141},{"key":101841,"count":25697},{"key":101842,"count":6213},{"key":101843,"count":1408}]}],"resultats":[{"#uriOffre":"offre?numeroOffre=163035045W"},{"#uriOffre":"offre?numeroOffre=163035043W"},{"#uriOffre":"offre?numeroOffre=163035044W"},{"#uriOffre":"offre?numeroOffre=162918884W"},{"#uriOffre":"offre?numeroOffre=162913997W"},{"#uriOffre":"offre?numeroOffre=163035042W"},{"#uriOffre":"offre?numeroOffre=162930465W"},{"#uriOffre":"offre?numeroOffre=162926697W"},{"#uriOffre":"offre?numeroOffre=163035041W"},{"#uriOffre":"offre?numeroOffre=163035040W"},{"#uriOffre":"offre?numeroOffre=163035039W"},{"#uriOffre":"offre?numeroOffre=163035036W"},{"#uriOffre":"offre?numeroOffre=163035032W"},{"#uriOffre":"offre?numeroOffre=163035031W"},{"#uriOffre":"offre?numeroOffre=163035030W"},{"#uriOffre":"offre?numeroOffre=163035029W"},{"#uriOffre":"offre?numeroOffre=163035027W"},{"#uriOffre":"offre?numeroOffre=163035026W"},{"#uriOffre":"offre?numeroOffre=163035022W"},{"#uriOffre":"offre?numeroOffre=163035020W"}]}"
I am trying to download a pdf using cURL and am getting stuck on a "Server Error in '/' Application" page. My code:
$url = "https://some.domain.com/Reports/Report?ReportID=123456"
$ch = curl_init($url);
$header = array ('Host: some.domain.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 4);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, implode(':', $arrayCiphers));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_COOKIE, "ASP.NET_SessionId=XXXXXXXX; __RequestVerificationToken_XXXXXXX=lots-of-alpha-numeric-characters");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_REFERER, "https://some.domain.com");
$output = curl_exec($ch);
echo $output;
curl_close($ch);
Is there something else I can try or some more debugging I can do?
[edit] Apparently it's caused by one of my parameters. There are several parameters in the URL. &Flag=True seems to be causing the error. If I change it to &Flag=False I get a blank page.
This error was being caused because my curl request header did not include cookies that were required to download the file. Adding those cookies in the header fixed it.
I am trying to get a website source with a curl call but some data is missing and I don't know what I'm doing wrong.
If i make a call to the url in browser in the page source will apear <!-- request captchas: blabla -->..
but after I call in php it will bring in the page source: "<!-- request captchas: null -->"
My code:
$url='http://www.anaf.ro/anaf/internet/ANAF/informatii_publice/informatii_agenti_economici/registrul_inactivi_reactivati/';
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=0001R8jflCwCXeYrmbF45vBxtS-:3KMDRVUOUV");
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close ($ch);
echo $html;
You forgot to add curl_init().
Do like this..
<?php
$url='http://www.anaf.ro/anaf/internet/ANAF/informatii_publice/informatii_agenti_economici/registrul_inactivi_reactivati/';
$ch = curl_init(); //<-------------- Add this here
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=0001R8jflCwCXeYrmbF45vBxtS-:3KMDRVUOUV");
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close ($ch);
echo $html;
Try removing this line:
curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=0001R8jflCwCXeYrmbF45vBxtS-:3KMDRVUOUV");