xref: /curl/docs/cmdline-opts/cookie.md (revision fe9f68fa)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Short: b
5Long: cookie
6Arg: <data|filename>
7Protocols: HTTP
8Help: Send cookies from string/load from file
9Category: http
10Added: 4.9
11Multi: append
12See-also:
13  - cookie-jar
14  - junk-session-cookies
15Example:
16  - -b "" $URL
17  - -b cookiefile $URL
18  - -b cookiefile -c cookiefile $URL
19  - -b name=Jane $URL
20---
21
22# `--cookie`
23
24Pass the data to the HTTP server in the Cookie header. It is supposedly the
25data previously received from the server in a `Set-Cookie:` line. The data
26should be in the format `NAME1=VALUE1; NAME2=VALUE2` or as a single filename.
27
28When given a set of specific cookies and not a filename, it makes curl use the
29cookie header with this content explicitly in all outgoing request(s). If
30multiple requests are done due to authentication, followed redirects or
31similar, they all get this cookie header passed on.
32
33If no `=` symbol is used in the argument, it is instead treated as a filename
34to read previously stored cookie from. This option also activates the cookie
35engine which makes curl record incoming cookies, which may be handy if you are
36using this in combination with the --location option or do multiple URL
37transfers on the same invoke.
38
39If the filename is a single minus ("-"), curl reads the contents from stdin.
40If the filename is an empty string ("") and is the only cookie input, curl
41activates the cookie engine without any cookies.
42
43The file format of the file to read cookies from should be plain HTTP headers
44(Set-Cookie style) or the Netscape/Mozilla cookie file format.
45
46The file specified with --cookie is only used as input. No cookies are written
47to that file. To store cookies, use the --cookie-jar option.
48
49If you use the Set-Cookie file format and do not specify a domain then the
50cookie is not sent since the domain never matches. To address this, set a
51domain in Set-Cookie line (doing that includes subdomains) or preferably: use
52the Netscape format.
53
54Users often want to both read cookies from a file and write updated cookies
55back to a file, so using both --cookie and --cookie-jar in the same command
56line is common.
57
58If curl is built with PSL (**Public Suffix List**) support, it detects and
59discards cookies that are specified for such suffix domains that should not be
60allowed to have cookies. If curl is *not* built with PSL support, it has no
61ability to stop super cookies.
62