cURL命令行登录(bash)


cURL command line login (bash)

我在cronjob上有一个bash脚本。

do 
curl -d "test=working" https:/mysite.com/test
echo "done" 
done

现在,它只是在我的网站上发布请求。

但现在我想在会员专用区域提出张贴请求2次

那么,我如何登录保持会话,并发布2次?我在手机上有一段时间无法测试,但它一直在困扰我。

do 
curl -d "uname=a&pass=b" https:/mysite.com/login
for run in {1..2}
do
curl -d "test=working" https:/mysite.com/memberarea
echo "done" 
done

这行得通吗?

您可以使用cookie:

curl -b cookies.txt -c cookies.txt -e website.com -d 'xx=yy' http://website.com/path/to/resource

CCD_ 1表示使用cookies.txt中的cookie,并且CCD_ 2意味着将cookie转储到cookies.txt。

因此,在脚本中使用curl时,请始终添加two选项,以便可以保留会话。

FYI:

do 
curl -b cookies.txt -c cookies.txt -e mysite.com -d "uname=a&pass=b" https:/mysite.com/login
for run in {1..2}
do
curl -b cookies.txt -c cookies.txt -e mysite.com -d "test=working" https:/mysite.com/memberarea
echo "done" 
done

如果您的网站使用cookie来保持经过身份验证的会话,则可以使用--cookie name=data传递身份验证用户名和密码,并使用--cookie-jar <filename>存储cookie。