0 Replies Latest reply: Aug 18, 2008 9:43 PM by 807589 RSS

    Unable to get cookies

      Hi ALl

      am trying to read cookies from a URL.
      I am always getting cookies array count as 0.
      Pls see code below:

      import java.io.FileOutputStream;
      import java.io.IOException;

      import org.apache.commons.httpclient.*;
      import org.apache.commons.httpclient.HttpMethod;
      import org.apache.commons.httpclient.methods.GetMethod;
      import org.apache.commons.httpclient.HttpClient.*;

      public class TestCookies {

           * @param args

           private static String url = "http://www.google.com";

           public static void main(String[] args) {

           HttpClient client = new HttpClient();
           HttpMethod method = new GetMethod(url);
           int statusCode = client.executeMethod(method);
           byte [] res = method.getResponseBody();
           Cookie[] cookie= client.getState().getCookies();
           FileOutputStream fos= new FileOutputStream("C:\\donepage.html");

           //release connection
           catch(IOException e) {

      If I change the above url to my company url,I will see cookies length as 0.

      I spent lot of time but couldnt figure out.

      If I open the google in fiefox i see 7 cookies but with my code am getting only 1 cookie named - PREF.
      For my company url nothing is coming

      ANy help would be appreciated.


      Edited by: sriyak on Aug 18, 2008 7:42 PM