Grab current session's cookie with cURL

17,133

Curl can handle that for you; there is an option to store the cookies in a cookiejar and use those in subsequent requests.

Here is an example from the main curl site, which uses cookies from a file cookies.txt to set some and at the same time stores new cookies in newcookies.txt.

http://curl.haxx.se/docs/httpscripting.html#Cookie_Basics

curl --cookie cookies.txt --cookie-jar newcookies.txt  http://www.example.com

When going through a login process, for example, one would reuse the cookies from cookie jar.

Share:
17,133
Nhoya
Author by

Nhoya

Updated on June 04, 2022

Comments

  • Nhoya
    Nhoya almost 2 years

    I'm working on a script that send a POST request to an URL, actually I'm sending the cookies manually in the header.. but how to take it from the current browser session?

    I used tcpdump and grep but it's really the wrong choice :,D Some suggestions?

    I wont take them from a file but from the browser session and without enter in the cookie path of the browser

  • Tom Fenech
    Tom Fenech over 9 years
    It would be useful to provide an example showing what you mean here, in case the link changes in future.
  • Nhoya
    Nhoya over 9 years
    Ok but this is the same to take from an input... I want to take the cookies from the browser session without go inside the cookie path
  • nlu
    nlu over 9 years
    So you were talking about your browser session all the time?
  • Nhoya
    Nhoya over 9 years
    Yes, i was sure i wrote it.. Sorry
  • nlu
    nlu over 9 years
    Sorry, I overlooked that: just export the cookies and use them with curl: askubuntu.com/questions/161778/…