bash wget post数据中的变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8599760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Variables in wget post data
提问by user1111098
I am working on a simple bash script to download images from the website Tumblr. The idea is to use read
to get login info from the user, and wget --post-data
to log in, and this is what I have:
我正在编写一个简单的 bash 脚本来从 Tumblr 网站下载图像。这个想法是用来read
从用户那里获取登录信息并wget --post-data
登录,这就是我所拥有的:
read -p "Tumblr login email: " EMAIL
read -p "Tumblr login password: " PASSWRD
wget --user-agent=Mozilla/5.0 --save-cookies cookies.txt --post-data 'email=$EMAIL&password=$PASSWRD' --no-check-certificate https://www.tumblr.com/login
However, it is sending "$EMAIL"
and "$PASSWRD"
instead of the strings for the variables, is there any way to get it to send values that have been inputted by the user?
但是,它正在发送"$EMAIL"
而"$PASSWRD"
不是变量的字符串,有没有办法让它发送用户输入的值?
回答by kev
change:
改变:
--post-data 'email=$EMAIL&password=$PASSWRD'
to:
到:
--post-data="email=$EMAIL&password=$PASSWRD"
bash manual about Quoting
: http://www.gnu.org/software/bash/manual/bashref.html#Quoting
bash 手册Quoting
:http: //www.gnu.org/software/bash/manual/bashref.html#Quoting
回答by SzB
important: Do not use :
重要:不要使用:
--header="Content-Type: text/xml"
together with --post-data. It will override
连同--post-data。它会覆盖
--header="Content-Type: application/x-www-form-urlencoded"
issued by wget. Post-data will not be received by HttpServlet
由 wget 发行。Post-data 不会被 HttpServlet 接收