Variables in wget post data

故事扮演 提交于 2019-11-29 05:03:48

问题


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:

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?


回答1:


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




回答2:


important: Do not use :

--header="Content-Type: text/xml" 

together with --post-data. It will override

--header="Content-Type: application/x-www-form-urlencoded" 

issued by wget. Post-data will not be received by HttpServlet



来源:https://stackoverflow.com/questions/8599760/variables-in-wget-post-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!