Answer the question
In order to leave comments, you need to log in
What is the correct way to get one-time code via URL?
I found a free API for Russian Railways and decided for myself and my education to write a simple telegram bot to search for tickets.
But I can't get the one-time code correctly. The essence is simple, first you need to send a request " https://pass.rzd.ru/timetable/public/ru?layer_id=5... }}"
where you need to substitute the necessary data and get a one-time RID code. It must be substituted into the next request and get JSON with the necessary information.
" https://pass.rzd.ru/timetable/public/ru?layer_id=5... }}"
Here is my code, and the problem is that I get a "used" code and rzd gives an error
{" result":"FAIL","type":"SESSION_EXPIRED","error":"Session has expired. Please
public void findTickets(String from,String to,String date) {
StringBuffer content = new StringBuffer();
try {
URL url = new URL("https://pass.rzd.ru/timetable/public/ru?layer_id=5827&dir=0&tfl=3&checkSeats=1&code0=" + from + "&dt0=" + date + "&code1=" + to);
URLConnection urlConnection = url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
content.append(line);
}
bufferedReader.close();
} catch (Exception e){
System.out.println("EROR "+e.getMessage());
}
JSONObject obj = new JSONObject(content.toString());
long rid=0;
rid=obj.getLong("RID");
try {
URL url = new URL("https://pass.rzd.ru/timetable/public/ru?layer_id=5827&rid="+rid);
URLConnection urlConnection = url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
while ((line=bufferedReader.readLine())!=null){
content.append(line);
}
bufferedReader.close();
}catch (Exception e){
System.out.println(e.getMessage());
}
System.out.println(content.toString());
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question