我在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
这会有用吗?
答案 0 :(得分:2)
你可以使用cookies:
curl -b cookies.txt -c cookies.txt -e website.com -d 'xx=yy' http://website.com/path/to/resource
-b(--cookie)
表示使用cookies.txt中的cookie,
并且-c(--cokie-jar)
表示将cookie转储到cookies.txt。
所以在脚本中使用curl
时总是添加两个选项,以便您可以保留会话。
供参考:
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
答案 1 :(得分:1)
如果您的网站使用cookie来保持经过身份验证的会话,您可以使用--cookie name=data
传递身份验证用户名和密码,并使用--cookie-jar <filename>
存储Cookie。