Login site using cURL

I am trying to login from cURL command line with the command

curl –data “username=user&password=pass&submit=Login” http://www.ip.com:8080/LoginApplication/Login.jsp

And after that trying to access inner page using

curl http://www.ip.com:8080/LoginApplication/Success.jsp

But I am getting redirected to error page because of not logged in.

What I am missing in my first command so that it can maintain the session?
I have my website locally hosted


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Well, you’ll need to store the session data in a cookie. You can use -c cookie_filename to create the cookie (add this to your login command). And then, for the other requests, you can read from the cookie with -b cookie_filename.

In example:

curl -s loginpage -c cookiefile -d "user=myself&pass=secure"
curl -s secretpage -b cookiefile


Notice many times loginpage is not the page you open with your web browser where you introduce your user and password. You’ll have to check where the form is posting that data to (search the <form> tag in the source code and the action=... attribute). So, for example, if you want to log in to https://criticker.com, loginpage is https://www.criticker.com/authenticate.php and not https://www.criticker.com/signin.php, which is the one you open with your browser.

A tampering plugin/extension for your browser may help you find the correct loginpage and all the data that is being posted to it (like hidden input fields in the form).

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments