How to send a cookie along with HttpGet in Java

11,969

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

Share:
11,969

Related videos on Youtube

ninjasense
Author by

ninjasense

Updated on June 04, 2022

Comments

  • ninjasense
    ninjasense almost 2 years

    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(MyCookieStorageClass.getCookie());
    httpClient.setCookieStore(store);
    
    HttpGet httpGet = new HttpGet("http://localhost/);     
    
    try {
        // Execute HTTP Get Request  
        HttpResponse response = httpclient.execute(httpGet);  
        String responseData = ResponseHandler.getResponseBody(response);
    } catch (IOException e) {
        e.printStackTrace();
    }
    
    • ninjasense
      ninjasense over 13 years
      This is actually the correct implementation for the HttpClient 4.0.1, I had just had not been getting the correct cookie.

Related