0

I have two curl commands to execute. The second command needs to "remember" the login made by the first one. I do not know about curl but I think the --cookie parameter is doing the job.

well, curl is not for me. I need to do the same in Java but I can't rely in the environment ( cannot invoke /bin/sh -c curl ).

How can I do the same "login and still logged in" method in Java?

Already read this and this but both are "login every time will use".

curl -k -d "email=some@email.com&password=mysecret" -X POST 'https://some.site.com/index.php?some=parameter' --cookie "cookies.txt" --cookie-jar "cookies.txt"

curl -k "https://some.site.com/index.php?some=parameter" --cookie "cookies.txt" --cookie-jar "cookies.txt" --output test.tif
Magno C
  • 1,922
  • 4
  • 28
  • 53
  • did you try using `HttpContext` class as in https://stackoverflow.com/questions/4166129/apache-httpclient-4-0-3-how-do-i-set-cookie-with-sessionid-for-post-request – kalimba Apr 24 '19 at 18:12
  • you basically need content of `cookies.txt` file and use it to `httppost.setHeader` for Apache Client>=4.5 you need to set domain as well `cookie.setDomain(".domain.com"); cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true");`. – kalimba Apr 24 '19 at 18:14
  • Nice. I Will give a try. – Magno C Apr 25 '19 at 01:52
  • Am I asking too much if you answer my question with a functional snipet using my examples? – Magno C Apr 25 '19 at 01:55

0 Answers0