Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you print received cookie info to stdout with curl?

How do you print received cookie info to stdout with curl?

According to the man pages if you use '-' as the file name for the -c --cookie-jar option it should print the cookie to stdout. The problem is I get an error:

curl: option -: is unknown 

an example of the command I am running:

curl -c --cookie-jar - 'http://google.com' 
like image 952
Brian Yeh Avatar asked Jan 30 '14 17:01

Brian Yeh


People also ask

How can I see cookies with curls?

curl has a full cookie "engine" built in. If you just activate it, you can have curl receive and send cookies exactly as mandated in the specs. tell curl a file to read cookies from and start the cookie engine, or if it is not a file it will pass on the given string. -b name=var works and so does -b cookiefile.

How do you post cookies with curl?

Cookies are passed to Curl with the --cookie "Name=Value" command line parameter. Curl automatically converts the given parameter into the Cookie: Name=Value request header. Cookies can be sent by any HTTP method, including GET, POST, PUT, and DELETE, and with any data, including JSON, web forms, and file uploads.

How do I print response headers in curl?

By default, curl doesn't print the response headers. It only prints the response body. To print the response headers, too, use the -i command line argument.

Does curl remember cookies?

Curl writes all cookies previously read from a specified file as well as all cookies received from remote server(s). If no cookies are known, no data will be written.


1 Answers

You get that error because you use in the wrong way that option. When you see in a man page an option like:

-c, --cookie-jar <file name> 

this mean that if you want to use that option, you must to use -c OR --cookie-jar, never both! These two are equivalent and, in fact, -c is the abbreviated form for --cookie-jar. There are many, many options in man pages which are designed in the same way.

In your case:

curl -c - 'http://google.com' 

--cookie-jar is given as argument for -c option, so, it's interpreted as a file name, not like an option (as you may think), and - remains alone which leads to error because curl, indeed, doesn't have such an option.

like image 185
Radu Rădeanu Avatar answered Oct 12 '22 16:10

Radu Rădeanu