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.



Shiva-KumarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
have you tried the -u switch for username and password?  Also sound like some variables might be missing either GET or POST?
nociSoftware EngineerCommented:
You may need  another -c to get more cookies.
And you may need -e  (--referer) that old the previous URL

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SuperdaveCommented:
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.
Shiva-KumarAuthor Commented:
Noci's switch has done the trick.  Thank you.

I was missing --referer.

Shiva-KumarAuthor Commented:
Thank you!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.