Link to home
Start Free TrialLog in
Avatar of Shiva-Kumar
Shiva-Kumar

asked on

CURL not retaining the session after login

Hi,

I am using CURL to login to a page which redirects to another page upon successful login.
The problem I am facing is, once the login is successful, the redirect page is taking me back to the login page with error code 302 - Page moved Temporarily.

I am using the following command to login
CURL.exe -c "cookies.txt" -d "username=xxxx&password=xxxx&submit=Login" -i http://login_Page.xx.com

**the above command logs me in and redirects back me to the login page where as it is suppose to show the page_to_post.xx.com page.

once the login is successful, i have to post the data to another page for which am using the following command which is redirecting me to same login page.
CURL.exe -b "cookies.txt" --form "field1=xxx" --form "field2=xxxx" -i http://page_to_post.xx.com 

NOTE: one thig I noticed which may be a relevant hint is when i am loged in to the page using hte browser and when i try to access the http://page_to_post.xx.com from another tab it redirects me to the login page.

Please help me to understand where i am going wrong here.



Avatar of Rob
Rob
Flag of Australia image

have you tried the -u switch for username and password?  Also sound like some variables might be missing either GET or POST?
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try using -c "cookies.txt" -b "cookies.txt" -L
on at least the first command and maybe both--maybe the server really wants you to follow that redirect to be logged in.
Avatar of Shiva-Kumar
Shiva-Kumar

ASKER

Noci's switch has done the trick.  Thank you.

I was missing --referer.

Thank you!!!!