tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Jsoup > Post Connection

Post Connection 

Jsoup is an open source java library for parsing and manipulating HTML with ease. Get the latest binaries from http://jsoup.org/. This requires the library jsoup-1.6.1.jar to be in classpath. The following example shows getting the PNR status by making HTTP Post request.

File Name  :  
com/bethecoder/tutorials/jsoup/tests/PostConnectTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.jsoup.tests;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class PostConnectTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    //Getting PNR status
    Document doc = Jsoup.connect(
        "http://www.indianrail.gov.in/cgi_bin/inet_pnrstat_cgi.cgi")
        
        .data("lccp_pnrno1""423")
        .data("lccp_pnrno2""4101443")
        .data("textPnrNumber""4234101443")
        .post();

    //System.out.println(doc.html());
    System.out.println(doc.select("table[id=center_table]"));
  }

}
   

It gives the following output,
File Name  :  OUTPUT
01<table width="100%" border="0" cellpadding="0" cellspacing="1" class="table_border" id="center_table">
02 <tbody>
03  <tr>
04   <td width="25%" class="heading_table_top">S. No.</td>
05   <td width="45%" class="heading_table_top">Booking Status <br /> (Coach No , Berth No., Quota)</td>
06   <td width="30%" class="heading_table_top">* Current Status <br />(Coach No , Berth No.)</td>
07  </tr>
08  <tr>
09   <td class="table_border_both"><b>Passenger 1</b></td>
10   <td class="table_border_both"><b>S9 , 55,GN </b></td>
11   <td class="table_border_both"><b> CNF </b></td>
12  </tr>
13  <tr>
14   <td class="heading_table_top">Charting Status</td>
15   <td colspan="3" align="middle" valign="middle" class="table_border_both"> CHART NOT PREPARED </td>
16  </tr>
17  <tr>
18   <td colspan="4"><font color="#1219e8" size="1"><b> * Please Note that in case the Final Charts have not been prepared, the Current Status might upgrade/downgrade at a later stage.</b></font></td>
19  </tr>
20 </tbody>
21</table>



 
  


  
bl  br