使用POST登录cURL

时间:2015-05-14 19:34:29

标签: forms post curl cookies

我对cURL没什么经验,我必须使用cURL登录网站,我认为最好的方法是通过POST方法,然后转到另一个URL并请求POST,在同一个"导航会话中# 34;,因为我只能访问登录的其他URL。

据我搜索,我需要一个cookie文件才能让我登录,所以我用这个命令来做到这一点:

curl --cookie cookies.txt --request POST 'http://example.com/' -F 'authenticity_token=TOKENWITHLETTERSNUMBERSANDSYMBOLS&uid=MYUSERNAME&password=MYPASSWORD&commit=Enter --request POST 'http://example.com/subpage#40' -F 'commit=Save'

但它没有用,可能是因为我每次输入网址时生成的真实性令牌都可以在HTML的这一部分访问:

<form action="/login/log" method="post"><div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value="e2IIs5+9p9bAqkE0gJ4nVJ5E+yhKGod2B9b1bj6VJNk=" /></div>
  <p><b>Login:</b> <input id="uid" name="uid" type="text" /></p>
  <p><b>Password:</b> <input id="password" name="password" type="password" /></p>
  <p id='submit'>
</form>

那么如何检索真实性标记值以在POST请求中使用它?此外,POST是最好的方法吗?

0 个答案:

没有答案