I'm trying to download a file from this URL in PHP with cURL.
https://www.geopoi.it/geopoiAPI/php/utils/omixml/getOMIXML.php?&t=p&f=KML&id=61932577_ras
I resolve the captcha of the form im PHP, I manage the cookies, etc, and then, when i'm going to download nothing happens. This is the response header:
HTTP/1.1 200 OK
Date: Thu, 25 Oct 2018 09:36:51 GMT
Server: Apache
X-Powered-By: PHP/5.4.15
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: must-revalidate
Pragma: no-cache
Content-Length: 0
Connection: close
Content-Type: text/html
This is my code:
curl_setopt ($curl, CURLOPT_URL, 'https://www.geopoi.it/geopoiAPI/php/utils/omixml/getOMIXML.php?&cf=RTRRTR89T55F205K&p1=5&p2=2&p3=5&cod='.$captcha.'&ok=2&t=p&f=KML&id=553423949_ras');
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_HEADER, 1);
curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($curl, CURLOPT_TIMEOUT, 300);
curl_setopt ($curl, CURLOPT_USERAGENT, 'any');
curl_setopt ($curl, CURLOPT_VERBOSE, true);
curl_setopt ($curl, CURLOPT_HTTPHEADER , [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Language: es-ES,es;q=0.9,en;q=0.8,it;q=0.7,gl;q=0.6,fr;q=0.5,de;q=0.4',
'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36',
'Cookie: '. self::COOKIE_NAME . '=' . $cookie,
'Connection: keep-alive',
'Host: www.geopoi.it',
'Upgrade-Insecure-Requests: 1']);
I don't understand because it works in my navigator but with cURL the call doesn't work.
Any idea??
Many thanks!
the core problem seems to be: your code doesn't seeem to handle refresh meta that the form is returning:
(...)
<meta http-equiv="refresh" content="0;url=getOMIXML.php?&t=p&f=KML&id=61932577_ras&cf=TSTTST80A01L152H&p1=1&p2=1&p3=1&cod=tnChb29&ok=2" />
(...)
The above is in the form respone <body>
. This means AFTER you query the form with your CURL, you need to scrap the response for the refresh meta and query that url with same request data again.
There was another posting similiar to this problem here: How follow meta redirect with curl and php? so feel free to give it a try.