Reputation: 56912
I need to use Apache HttpClient (4.x) to make 3 consecutive web calls and essentially log me into my app programmatically:
http://myapp01.example.com
)JSESSIONID
"JSESSIONID
as a request cookie)JSESSIONID
.http://myapp01.example.com/fizz
), again using the same JSESSIONID
as a request cookieThe first GET's response will contain a cookie named JSESSIONID
. The POST will then log me in to the server (sending username and password data in the POST request body). This POST will also send (Set-Cookie
) the JSESSIONID
cookie received from the first GET. If my logins are successful, the JSESSIONID
will now be authenticated, and I am logged in. I can then make the 2nd GET call (still using the same JSESSIONID
) to /fizz
which is ordinarily an authenticated URL.
Can this be done in HttpClient 4? I see there is a method HttpClient.getCookieStore()
. but this seems to only store cookies per GET/POST/PUT/etc.
Any ideas as to how I can get this holding cookies across multiple requests, such that any cookies returned by the server are then added to subsequent requests?
Upvotes: 1
Views: 3566
Reputation: 27538
Apache HttpClient takes care of that automatically (since version 2)
Upvotes: 3