我正在尝试通过curl发送post请求,所以我运行了
curl --cookie /tmp/cookies.txt --cookie-jar /tmp/cookies.txt --data "name=value" http://www.mysite.com > post_request.txt
我将在 chrome 控制台中找到的 cookie 存储在/tmp/cookies.txt 中。后者有一个名称和一个值。我应该使用特定的格式在/tmp/cookies.txt 中写入 cookie 参数吗? (因为我只输入了值并没有起作用)
最佳答案
查看 curl 的手册页它说:
The file format of the file to read cookies from should be plain HTTP headers or the Netscape/Mozilla cookie file format.
查找您找到的 mozilla 格式:
http://xiix.wordpress.com/2006/03/23/mozillafirefox-cookie-format/
<domain> <TRUE|FALSE> <PATH> <TRUE|FALSE> <TIMESTAMP> <NAME> <VALUE>
(制表符分隔)
Domain: the domain that set & can subsequently read the cookie. This could include subdomains, e.g., .google.com means that local.google.com, news.google.com, whatever.google.com could possibly read the cookie, based on the next flag.
Flag: either TRUE or FALSE, whether or not all machines under that domain can read the cookie’s information.
Path: the root path under the domain where the cookie is valid. If this is /, the cookie is valid for the entire domain.
Secure Flag: either TRUE or FALSE, whether or not a secure connection (HTTPS) is required to read the cookie.
Expiration Timestamp: the “Unix Time” in seconds when the cookie is set to expire.
Name: the name of the value that the cookie is storing/saving.
Value: the value
(当然,您也可以仅使用所述的纯 HTTP header 。)
关于linux - cookie 是如何工作的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14429616/