views:

207

answers:

1

I have to login to a page using three parameters, after that I have to POST two parameters to another page inside the site I've just logged in.

So far I've got a cookie with this:

curl -c cookie.txt -d "username=username&pwd=pwd&domain=mydomain" http://myurl

...inside of the cookie I have a JSESSION id. I use the cookie as follows:

curl -b cookie.txt -d "par=value" http://myurlnumbertwo

Problems:

  • even after a POST to the login url I get in the console the HTML code of the login page, does this mean that the login did not succeed? How can I find the error that caused this, maybe a log?
  • after a successful login how do I remain in the login session and POST my parameters to the other page?

EDIT:

I finally got this working after stran's hint, follows the code.

  • POST_DATA contains the exact encoded string that was posted, as in 'parameter1=value1&parameter2=value2'
  • ACTION_URL contains the full URL to which the form is posted, as in http://stackoverflow.com/users/login

First I did a

wget --save-cookie cookie.txt --post-data 'POST_DATA' ACTION_URL

to make the login and save the cookie, followed by a:

wget --load-cookie cookie.txt --post-data 'POST_DATA' ACTION_URL

to make the POST I needed, thank you again for the hint ^^

+1  A: 

I'd give wget a try. There is a --save-cookies and --load-cookies option that allows you to use a cookie file. There's also a facility for handling session cookies, --keep-session-cookies. Refer to the wget man page for more :)

Personally, I've had much better luck with post through wget.

GL!

stran
Thank you for the reply, I'll give it a try ^^
Alberto Zaccagni
Montecristo, how did that work out for you?
Jim
Thank you so much for the hint stran, I finally got that working... I'll edit the post for the others... :]
Alberto Zaccagni
Fantastic, glad it worked for you!
stran