Cześć!
Próbuję napisać robota który z dostępnych danych pobierze mi raport z "historiapojazdu.gov.pl". Posiadam VIN, Numer rejestracyjny oraz datę pierwszej rejestracji na świecie.
$url = "https://historiapojazdu.gov.pl/";
$vin = "WDD2462001J020815";
$numer_rejestracyjny = "WSE9KU1";
$data_pierwszej_rejestracji = date("2012-03-01");
function curl($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
$content = curl_exec($curl);
$resultUrl = explode('<form id="_historiapojazduportlet_WAR_historiapojazduportlet_:formularz" name="_historiapojazduportlet_WAR_historiapojazduportlet_:formularz" method="post" action="', $content);
$resultUrl = explode('"', $resultUrl[1]);
$resultViewState = explode('<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="', $content);
$resultViewState = explode('"', $resultViewState[1]);
$postUrl = $resultUrl[0];
$viewState = $resultViewState[0];
return array("postURL"=>$postUrl, "javax.faces.ViewState"=>$viewState);
}
function sendPost($url, $numerRejestracyjny, $numerVIN, $dataPierwszejRejestracji) {
$array = curl($url);
$encodedUrl = "https://historiapojazdu.gov.pl/strona-glowna?p_p_id=historiapojazduportlet_WAR_historiapojazduportlet&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_cacheability=cacheLevelPage&p_p_col_id=column-1&p_p_col_count=1&_historiapojazduportlet_WAR_historiapojazduportlet__jsfBridgeAjax=true&_historiapojazduportlet_WAR_historiapojazduportlet__facesViewIdResource=%2Fviews%2Findex.xhtml&_historiapojazduportlet_WAR_historiapojazduportlet_javax.faces.ViewState=".urlencode($array['javax.faces.ViewState'])."&_historiapojazduportlet_WAR_historiapojazduportlet_:vin=".urlencode($numerVIN)."&_historiapojazduportlet_WAR_historiapojazduportlet_:data=".$dataPierwszejRejestracji."%2C&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_lifecycle=2&_historiapojazduportlet_WAR_historiapojazduportlet_:rej=".$numerRejestracyjny."&_historiapojazduportlet_WAR_historiapojazduportlet_:formularz=_historiapojazduportlet_WAR_historiapojazduportlet_%3Aformularz&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_mode=view&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_cacheability=cacheLevelPage&_historiapojazduportlet_WAR_historiapojazduportlet_let__jsfBridgeAjax=true&_historiapojazduportlet_WAR_historiapojazduportlet__facesViewIdRender=%2Fviews%2Findex.xhtml&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_col_id=column-1&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_state=normal&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_col_count=1&_historiapojazduportlet_WAR_historiapojazduportlet_let__facesViewIdResource=%2Fviews%2Findex.xhtml&_historiapojazduportlet_WAR_historiapojazduportlet_javax.faces.encodedURL=https%3A%2F%2Fhistoriapojazdu.gov.pl%2Fstrona-glowna%3Fp_p_id%3Dhistoriapojazduportlet_WAR_historiapojazduportlet";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $array['postURL']);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, "javax.faces.ViewState=".$array['javax.faces.ViewState']."&_historiapojazduportlet_WAR_historiapojazduportlet_:rej=".$numerRejestracyjny."&_historiapojazduportlet_WAR_historiapojazduportlet_:vin=".$numerVIN."&_historiapojazduportlet_WAR_historiapojazduportlet_:data=".$dataPierwszejRejestracji."&_historiapojazduportlet_WAR_historiapojazduportlet_:formularz=_historiapojazduportlet_WAR_historiapojazduportlet_:formularz&javax.faces.encodedURL=".$encodedUrl."&_historiapojazduportlet_WAR_historiapojazduportlet_:btnSprawdz=1");
$content = curl_exec($curl);
return $content;
}
//zmienne do przesłania
//method="post"
//action=$postUrl
//enctype="application/x-www-form-urlencoded"
print sendPost($url, $numer_rejestracyjny, $vin, $data_pierwszej_rejestracji);
Niestety po wysłaniu danych poprzez POST ukazuję się BLANKPAGE :((