同福

curl命令行传递Cookie参数的方法【20221009】

介绍

介绍

福哥要在使用curl请求接口的时候加上cookie参数怎么办?

教程

格式

其实通过curl --help就能知道怎么弄了。

home/topic/2022/1008/16/0b0ac99398616c3b03e60754775abd01.png

通过文件传递

编辑一个cookie.txt文本文件,加入cookie设置内容,格式如下:

[域名]    FALSE    [URI]    FALSE    [过期时间Unix时间戳]    [变量名称]    [变量值]

福哥把前面的例子写成了cookie.txt格式,内容如下:

localhost	FALSE	/	FALSE	0	uid	35
localhost	FALSE	/	FALSE	0	uname	tongfu.net

现在福哥使用cookie.txt文件想接口传递cookie参数。

curl -i --cookie cookie.txt "http://localhost/api/status"

home/topic/2022/1008/16/281d4eaf198cd6e7f06a4179fae0380e.png