开发者

how to call a form based authentication from curl or wget

开发者 https://www.devze.com 2023-03-25 18:10 出处:网络
I want to call an url usingcurl and wget 开发者_JAVA技巧I tried wget --save-cookies cookies.txt --post-data \'user=foo&password=bar\'

I want to call an url using curl and wget

开发者_JAVA技巧

I tried wget --save-cookies cookies.txt --post-data 'user=foo&password=bar' http://server.com/Login

wget --load-cookies cookies.txt -p http://server.com/interesting/article.jsp

But the login form is not accepting post data.Any other way i can try this?


I was able to find partial solution using load cookies with wget.
Here is Google Chrome extension to export cookies Chrome Google Export Extension
use this cookie with wget

  1. Install Google Chrome Extension.
  2. Login to site via Google Chrome
  3. Export Cookie using Chrome extension
  4. Somewhere may be same place where wget or desktop.
  5. now run following wget command with full path to cookies.txt

Example

wget -x --load-cookies C:\Users\Documents\GnuWin32\bin\cookies.txt http://example.com/some_interesting/article/1.html


Good Luck


For the record: Mowgli's solution did not work for me (no Chrome in my environment), so after some digging I found the issue: form-based authentication usually sets session cookies, but wget does not saves them by default. So using a command like

wget --keep-session-cookies --save-cookies /tmp/cookiefile --post-data='username=User&password=Pwd123' <login URL>

or somewhat safer

wget --keep-session-cookies --save-cookies /tmp/cookiefile --post-file creds <login URL>

where the file creds would contain the same pair username=User&password=Pwd123 (no end-of-line!) does the job. Then --load-cookies /tmp/cookiefile should be accepted by the site.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号