Apache HttpClient 4.0.3 - how do I set cookie with sessionID for POST request?

后端 未结 4 1062
梦毁少年i
梦毁少年i 2020-11-27 02:38

can you tell me how to store jsessionid in cookie, so it can be passed to the servlet with post request? I\'m using Apache HttpClient version 4.0.3. All the solutions I\'ve

4条回答
  •  鱼传尺愫
    2020-11-27 03:11

    I am so glad to solve this problem:

    HttpPost httppost = new HttpPost(postData); 
    CookieStore cookieStore = new BasicCookieStore(); 
    BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", getSessionId());
    
    //cookie.setDomain("your domain");
    cookie.setPath("/");
    
    cookieStore.addCookie(cookie); 
    client.setCookieStore(cookieStore); 
    response = client.execute(httppost); 
    

    So Easy!

提交回复
热议问题