使用curl发送cookie
我正在使用curl来检索cookie,如下所示:
curl -c cookies.txt url
然后我从cookies.txt文件中解析我想要的cookie并使用cookie再次发送请求
curl -b "name=value" url
这是发送cookie的正确方法吗? 有没有更简单的方法?
I am using curl to retrieve cookies like so:
curl -c cookies.txt url
then I parse the cookie I want from the cookies.txt file and send the request again with the cookie
curl -b "name=value" url
Is this the correct way to send the cookie?
Is there a simpler way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您还可以使用
-b
指定从中读取 cookie 的 cookie 文件。在许多情况下使用 -c 和 -b 到同一个文件就是你想要的:
进一步
仅使用 -c 将使curl启动没有cookies但仍然解析和理解cookies并且如果使用重定向或多个 URL,它将在单次调用中使用收到的 cookie,然后最终将它们全部写入输出文件。
-b 选项将一组初始 cookie 提供给curl,以便它在启动时了解它们,并激活curl 的 cookie 解析器,以便它也解析和使用传入的 cookie。
另请参阅
Everything curl< 中的 cookie 章节 /em> 书。
You can also use
-b
to specify a cookie file from which to read the cookies.In many situations using -c and -b to the same file is what you want:
Further
Using only -c will make curl start with no cookies but still parse and understand cookies and if redirects or multiple URLs are used, it will then use the received cookies within the single invoke before it writes them all to the output file in the end.
The -b option feeds a set of initial cookies into curl so that it knows about them at start, and it activates curl's cookie parser so that it'll parse and use incoming cookies as well.
See Also
The cookies chapter in the Everything curl book.
.example.com TRUE / FALSE 1560211200 MY_VARIABLE MY_VALUE
cookies 文件格式显然由每个 cookie 一行组成,每行由以下七个制表符分隔字段组成:
来自 http://www.cookiecentral.com/faq/#3.5
.example.com TRUE / FALSE 1560211200 MY_VARIABLE MY_VALUE
The cookies file format apparently consists of a line per cookie and each line consists of the following seven tab-delimited fields:
From http://www.cookiecentral.com/faq/#3.5
如果您在 Firefox 上安装了 Firebug,只需打开该 url。在网络面板中,右键单击并选择复制为 cURL。您可以看到此 Web 调用的所有curl 参数。
if you have Firebug installed on Firefox, just open the url. In the network panel, right-click and select Copy as cURL. You can see all curl parameters for this web call.
很烦人,官网没有cookie文件exmpale https://ec.haxx.se/http /http-cookies。
最后,我发现它不起作用,如果你的文件内容只是像这样复制,
我猜格式必须看起来像 @Agustí Sánchez 所说的样式
。您可以通过-c在网站上创建cookie文件来测试它。
所以尝试这种方式,它有效
你可以从 chrome 控制台网络选项卡复制 cookie。
Very annoying, no cookie file exmpale on the official website https://ec.haxx.se/http/http-cookies.
Finnaly, I find it does not work, if your file content is just copyied like this
I gusess the format must looks the style said by @Agustí Sánchez
. You can test it by -c to create a cookie file on a website.
So try this way, it works
You can just copy the cookie from chrome console network tab.