Answer the question
In order to leave comments, you need to log in
PHP: How to correctly send a date in a POST request?
Please help me with the task.
I am making a PHP script to send a POST request to the official website of the Ukrainian Railways to get information about the availability of trains.
But I constantly get in response "Invalid departure date entered"
The script parses the session id with cookies and the token is also on the site with tickets
. I also looked at what the browser sends to the server.
And entered the same parameters and header.
In short, this is the request:
// Пост запрос
$url = 'http://booking.uz.gov.ua/ru/purchase/search';
$data = array('station_id_from' => '2200001',
'station_id_till' => '2208001',
'station_from' => '%D0%9A%D0%B8%D0%B5%D0%B2',
'station_till' => '%D0%9E%D0%B4%D0%B5%D1%81%D1%81%D0%B0',
'date_dep' => '20.06.2015',
'time_dep' => '00%3A00',
'time_dep_till' => '',
'another_ec' => '0',
'search' => '');
$options = array(
'http' => array(
'header' => "Host: booking.uz.gov.ua\r\n".
"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0\r\n".
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8\r\n".
"Accept-Language: uk,ru;q=0.8,en-US;q=0.5,en;q=0.3\r\n".
"Accept-Encoding: gzip, deflate\r\n".
"DNT: 1\r\n".
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n".
"GV-Ajax: 1\r\n".
"GV-Referer: http://booking.uz.gov.ua/ru/\r\n".
"GV-Screen: 1280x800\r\n".
"GV-Token: $uz->token\r\n".
"GV-Unique-Host: 1\r\n".
"Referer: http://booking.uz.gov.ua/ru/\r\n".
"Content-Length: 208\r\n".
"Cookie: HTTPSERVERID=$uz->cookie_gv_server_n;_gv_sessid=$uz->cookie_gv_sessid;_gv_lang=ru;__utma=31515437.1166281925.1433453305.1433453305.1433453305.1;__utmb=31515437.1.10.1433453305;__utmc=31515437;__utmz=31515437.1433453305.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmt=1\r\n".
"Connection: keep-alive\r\n".
"Pragma: no-cache\r\n".
"Cache-Control: no-cache\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
// Обработка результатов
$inp = $result;
$s = preg_replace('/\\\u0([0-9a-fA-F]{3})/','&#x\1;',$inp);
$s = html_entity_decode($s, ENT_NOQUOTES, 'UTF-8');
$s = json_decode($s);
print_r($s->value);
Answer the question
In order to leave comments, you need to log in
I do not see any problems with the date.
<?PHP
$ch = curl_init('http://booking.uz.gov.ua/ru/purchase/search/');
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array
(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8',
'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,bg;q=0.2',
'Accept-Encoding: gzip, deflate',
'GV-Token: b8efd7256505869cb98c30777dd47aa2',
'GV-Unique-Host: 1',
'Content-Type: application/x-www-form-urlencoded',
'GV-Ajax: 1',
'Proxy-Connection: keep-alive',
'Host: booking.uz.gov.ua',
'Cookie: _gv_sessid=91r5trgpl6068343um8vmjscs2; _gv_lang=ru; HTTPSERVERID=server2; __utmt=1; __utma=31515437.2137620103.1434828433.1434828433.1434828433.1; __utmb=31515437.2.10.1434828433; __utmc=31515437; __utmz=31515437.1434828433.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)',
'Referer: http://booking.uz.gov.ua/ru/',
'GV-Screen: 1920x1080',
'GV-Referer: http://booking.uz.gov.ua/ru/',
'Accept: */*'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'station_id_from=2401406&station_id_till=2020891&station_from=%D0%91%D0%B8%D0%B3%D0%B0%D0%B9%D0%BB%D1%8F%D0%B9&station_till=%D0%9C%D0%B0%D0%B2%D1%80%D0%B8%D0%BD%D0%BA%D0%B0&date_dep=21.06.2015&time_dep=00%3A00&time_dep_till=&another_ec=0&search=');
curl_exec($ch);
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question