I need some help with setting up a cURL request to a page. In the netherlands we have this site ‘RDW.NL’ which gives you the opportunity to check up a vehicle’s details by entering the licence plate number.
For businesses, there is a paid alternative to request large amounts of data, but the costs are too high (€1050 + €0,50 per request) to pay this since it’s just for personal use and for testing purposes only.
Recently they changed their website and the old scripts stopped working, so I decided to give it a try myself but I’m kind of stuck.
Here’s what I have so far:
<?php
$ckfile = "/tmp/rdwcookie.txt";
# Setup first URL
$ch = curl_init("https://ovi.rdw.nl/Default.aspx");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
$input = curl_exec($ch);
# Get VIEWSTATE variable
preg_match('/id="__VIEWSTATE" value="(.*)" \/>/i', $input, $__VIEWSTATE);
preg_match('/Set-Cookie: ISAWPLB{(.*)}={(.*)};/i', $input, $__COOKIES);
preg_match('/Set-Cookie: ASP.NET_SessionId=(.*);/i', $input, $__ASPNET);
#echo $input;
# Set options for RDW Call
$options = array(
'ctl00$ctl00$PlaceHolderMainContent$PlaceHolderMainContent$txtKenteken' => '16-JS-GK',
'ctl00%24ctl00%24PlaceHolderMainContent%24PlaceHolderMainContent%24btnZoeken' => 'Zoeken',
'__VIEWSTATE' => $__VIEWSTATE[1],
'__EVENTTARGET' => '',
'__EVENTARGUMENT' => ''
);
#echo file_get_contents($ckfile);
# Setup second URL
$ch = curl_init("https://ovi.rdw.nl/VoertuigDetails.aspx");
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIE, 'ISAWPLB{'.$__COOKIES[1].'}='.$__COOKIES[2].'; ASP.NET_SessionId='.$__ASPNET[1]);
#curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
$data = curl_exec($ch);
# Echo data
echo $data;
?>
At the first page I try to save all cookies (which works), but sending the CURLOPT_COOKIEFILE does not show up any cookies in the headers of the cURL request. Therefor I used CURLOPT_COOKIE with some preg_matches to get the cookies manually and send them along (this works).
Also the post variables are right.
However, it still complains that the service is offline when I echo $data, this could be the case of course, but when visiting the page and entering some data manually it works perfectly.
So, is there something I’m missing? I can’t seem to get the right page loaded with cURL.
Any help would be appreciated.
Used a different source, the SSL was interfering with getting the right response. It works properly with the given example. Thanks for thinking tho.