使用 curl 发送 cookie [英] Send cookies with curl

查看:72
本文介绍了使用 curl 发送 cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 curl 来检索 cookie,如下所示:

I am using curl to retrieve cookies like so:

curl -c cookies.txt url

然后我从 cookies.txt 文件中解析出我想要的 cookie 并用 cookie 再次发送请求

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 

这是发送 cookie 的正确方式吗?有没有更简单的方法?

Is this the correct way to send the cookie? Is there a simpler way?

推荐答案

您也可以使用 -b 指定一个 cookie 文件来读取 cookie.

You can use -b to specify a cookie file to read the cookies from as well.

在许多情况下使用 -c-b 到同一个文件就是你想要的:

In many situations using -c and -b to the same file is what you want:

curl -b cookies.txt -c cookies.txt http://example.com

进一步

仅使用 -c 将使 curl 开始时没有 cookie 但仍然解析和理解 cookie,如果使用重定向或多个 URL,它将在单个调用中使用接收到的 cookie,然后将它们全部写入输出文件结束.

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.

-b 选项将一组初始 cookie 提供给 curl,以便它在开始时知道它们,并激活 curl 的 cookie 解析器,以便它也解析和使用传入的 cookie.

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.

另见

Everything curl 书中的 cookie 章节.

这篇关于使用 curl 发送 cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆