When I wanted to get the PNR(Passenger Name Record) status programmatically, it can be done only using third party API’s. But none of the third party API’s are free and even if it is free then number of pnr status per day is limited. So I googled for java code to get the PNR status. I could able to see many links and programs, but as of today nothing is working.
Finally I took some code base from stack overflow and started writing the executable code,
- Apache-httpcomponents-httpcore Jar
- jSoup Jar
PNR Live Status using Java:
String captcha = "24357"; String pnr1 = "4738866122"; String reqStr = "lccp_pnrno1=" + pnr1 + "&lccp_cap_value=" + captcha + "&lccp_capinp_value=" + captcha + "&submit=Please+Wait..."; StackOverflowPNR check = new StackOverflowPNR(); StringBuffer data = check.getPNRResponse(reqStr, "http://www.indianrail.gov.in/cgi_bin/inet_pnstat_cgi_1738.cgi"); // giving the html output response string to jsoup Document doc = Jsoup.parse(data.toString()); String pnrNumber = null; /* Retrieving the PNR Number starts */ pnrNumber = doc.select("td.Enq_heading").text(); String subStrTillNumber = pnrNumber.substring(("You Queried For : PNR Number : ".length()), pnrNumber.length()); String onlyPNRNumber = subStrTillNumber.substring(0, subStrTillNumber.indexOf("(E - TICKET)")); String finalPNR = onlyPNRNumber.replaceAll("-", ""); //System.out.println(finalPNR); /* Retrieving the PNR Number ends */
PNR Status Java Program Output:
TRAIN_NAME CHENNAI EXPRESS
BOARDING_DATE 30- 4-2016
Pass Name:::Passenger 1
Booking status:::W/L 35,GNWL
Current Status:::W/L 7
Pass Name:::Passenger 2
Booking status:::W/L 36,GNWL
Current Status:::W/L 8
Download the Code:
Above, I gave the sample snippet and the overview of the PNR Live Status program.
Note: I took some sample PNR number and when you are testing this program give some correct PNR number and run the program to get the PNR Live status.
Feel free to mention your comments/suggestions/feedbacks in the below comments section.
2,761 total views, 1 views today