php - cURL 命令行登录 (bash)

标签 php linux bash curl

我在 cronjob 上有一个 bash 脚本。

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

现在,它只是在我的网站上发出一个帖子请求。

但是现在我想在成员(member)专区发帖请求2次

那么我怎样才能登录保持 session ,并发布 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

这行得通吗?

最佳答案

您可以使用 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 时总是添加这两个选项,这样你就可以保持 session 。

仅供引用:

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

关于php - cURL 命令行登录 (bash),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20533285/

相关文章:

php - 是否可以在没有 curl 和 wget 的情况下将数据发布/获取到 TLSv1.1+ 安全站点?

c++ - Linux GUI 开发

linux - 流重定向顺序和操作系统执行的详细信息

linux - 检查一个数字是否是 bash 中的质数

bash - 在不解析符号链接(symbolic link)的情况下获取完整路径?

bash - “bad interpreter: Operation not permitted” El Capitan 错误

php - 在php中使用静态类变量作为类名调用静态方法

PHP 在页面之间传递消息

java - 从 Linux EXTREME VPS 读取文件时出现文件未找到异常

javascript - 在定义之前就使用了tinymce