Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

EDIT:

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 http://criticker.com, loginpage is http://www.criticker.com/authenticate.php and not http://www.criticker.com/signin.php, which is the one you open with your browser.

If you use Firefox, a plugin like Tamper may help you find the correct loginpage and all the data that is being posted to it (like hidden input fields in the form).

share|improve this answer
    
Given sequence of -s -c -d doesnot even producing cookie file –  SAR Jun 23 at 9:49
    
It was a great help, I looked my source again and found my request is going to a controller and then I modified my command and it worked for me. –  SAR Jun 23 at 10:42
    
This works fine for HTTP, is there anything I need to do extra with HTTPS –  SAR Jun 23 at 12:20
    
@SAR: you are having problems with certificates. Maybe you just want to use -k. See curl --help for more information or search on the internet how to handle certificates. ;-) –  Peque Jun 26 at 11:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.