private RailyatriCookies getRailyatriCookies() {

    String railyatriUrl = TRAIN_ENQUIRY_SERVER;
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(railyatriUrl);
    RailyatriCookies railyatriCookies = null;
    try {

      HttpResponse httpResponse = httpClient.execute(httpGet);

      if (httpResponse.getStatusLine().getStatusCode() == 200) {
        railyatriCookies = new RailyatriCookies();
        railyatriCookies.setCookieSpecRegistry(httpClient.getCookieSpecs());
        railyatriCookies.setCookieStore(httpClient.getCookieStore());

        // For debugging only
        List<Cookie> cookies = railyatriCookies.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
          System.out.println("No Cookies!!!");
        } else {
          for (int i = 0; i < cookies.size(); i++) {
            System.out.println("-" + cookies.get(i).toString());
          }
        }
      }
    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return railyatriCookies;
  }
Ejemplo n.º 2
0
 private static void processCookieRejected(DefaultHttpClient client) {
   client.getCookieSpecs().register("esay", new EasyCookieSpecFactory());
   client.getParams().setParameter(ClientPNames.COOKIE_POLICY, "esay");
 }