CURL to access a page that requires a login from a different page

前端 未结 4 1717
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 08:53

I have 2 pages: xyz.com/a and xyz.com/b. I can only access xyz.com/b if and only if I login to xyz.com/a first. If access

4条回答
  •  一向
    一向 (楼主)
    2020-11-27 09:32

    My answer is a mod of some prior answers from @JoeMills and @user.

    1. Get a cURL command to log into server:

      • Load login page for website and open Network pane of Developer Tools
        • In firefox, right click page, choose 'Inspect Element (Q)' and click on Network tab
      • Go to login form, enter username, password and log in
      • After you have logged in, go back to Network pane and scroll to the top to find the POST entry. Right click and choose Copy -> Copy as CURL
      • Paste this to a text editor and try this in command prompt to see if it works
        • Its possible that some sites have hardening that will block this type of login spoofing that would require more steps below to bypass.
    2. Modify cURL command to be able to save session cookie after login

      • Remove the entry -H 'Cookie: '
      • Add after curl at beginning -c login_cookie.txt
      • Try running this updated curl command and you should get a new file 'login_cookie.txt' in the same folder
    3. Call a new web page using this new cookie that requires you to be logged in

      • curl -b login_cookie.txt

    I have tried this on Ubuntu 20.04 and it works like a charm.

提交回复
热议问题