我在尝试使用curl连接到网站时遇到了一些麻烦,可能还有cookie。
以下是该网站的auth html:
<div id="authorize">
<form action="/" method="post" id="user-login" accept-charset="UTF-8"><div><div class="my-form-wrapper">
<div class="form-item form-type-textfield form-item-name">
<input type="text" id="edit-name" name="name" value="" size="60" maxlength="60" class="form-text required" /> <label class="option" for="edit-name">E-mail Address <span class="form-required" title="This field is required.">*</span></label>
<div class="description">Please enter your E-mail Address.</div>
</div>
<div class="form-item form-type-password form-item-pass">
<input type="password" id="edit-pass" name="pass" size="60" maxlength="128" class="form-text required" /> <label class="option" for="edit-pass">Password <span class="form-required" title="This field is required.">*</span></label>
<div class="description">Enter your Password.</div>
</div>
<input type="hidden" name="form_build_id" value="form-Jrv1EcWkN7AHVeYQoKEGjmtx5OSIcfcS7BbLp4vPB7k" />
<input type="hidden" name="form_id" value="user_login" />
<div class="login-forgot"><a href="/user/password">Forgot?</a></div><input type="hidden" name="dest_page" value="/home" />
<div class="form-actions form-wrapper" id="edit-actions"><input type="submit" id="edit-submit" name="op" value="Log in" class="form-submit" /></div></div></div></form>
<div class="register"><a href="/user/register">Register</a></div>
</div>
我认为要传递的正确数据是这样的:
(对于此示例,我的电子邮件= myname@email.com
,我的密码= mypass!
)
curl -d "name=myname%40email.com&pass=mypass%21&form_build_id=form-Jrv1EcWkN7AHVeYQoKEGjmtx5OSIcfcS7BbLp4vPB7k&form_id=user_login&dest_page=%2Fhome&op=Log+in" https://mywebsite.com
我遇到两个问题。
1)每次curl
网站时,都会生成新的form_build_id
2)我无法判断我的登录是否正常,我是否应将@
转换为%40
和!
转换为%21
以获取我的用户名和密码?
答案 0 :(得分:0)
如果您想要一个可以在一次通话中进行解析/请求构建/重新发送的工具,您可以使用我的Xidel:
xidel https://mywebsite.com -f 'form((//form)[1], {"name": "myname", "pass": "mypass"})' --download -
答案 1 :(得分:0)
token=$(curl -b $cookie_path -c $cookie_path --request GET "$site_url/services/session/token" -s)
curl -H "X-CSRF-Token: $token" -b $cookie_path -c $cookie_path -d "username=$username&password=$password" "$login_url" -s
token=$(curl -b $cookie_path -c $cookie_path --request GET "$site_url/services/session/token" -s)