views:

243

answers:

2

I am trying to send a cookie along with my HttpGet request, but everytime I try I havent been able to successfully send it. I also tried to modify the headers directly, here is my code:

        DefaultHttpClient httpclient = new DefaultHttpClient();  

    CookieStore store = new BasicCookieStore();
    store.addCookie(Authentication.getCookie());
    httpclient.setCookieStore(store);

    HttpGet httpget = new HttpGet("http://localhost:8080/Search/);  

    //httpget.addHeader("Cookie", Authentication.getCookie().toString());   


    //httpget.addHeader((Header) Authentication.getCookie());




    try {
        // Execute HTTP Get Request  
        HttpResponse response = httpclient.execute(httpget);  

      String responseData = ResponseHandler.getResponseBody(response);


    } catch (IOException e) {
        e.printStackTrace();
    }
A: 

this is an example that I used as a basis for my cookie functionality in my application.

http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/CookieDemoApp.java?view=markup

Aaron Saunders
This is the correct implementation for HttpClient 3, although I was looking for the newest version of the HttpClient package. Read the comment below the OP for correct HttpClient 4.0.1 implementation
ninjasense
A: 

This is actually the correct implementation for the HttpClient 4.0.1, I had just had not been getting the correct cookie.

ninjasense