in reply to Small problem with handling cookies

It seems to me you're not sending the cookie back to the server. Or do you? You're not showing the code that does it.

And it seems you are sending POST parameters in the URL (ie treating them as GET), instead of using $ua->post to actually post them.