Your code looks mostly ok, but you're not going to be looking for Set-Cookie in your request... that's what the server would return. You're gonna be sending a Cookie: header. What are you seeing in your debugging?
--isotope
http://www.skylab.org/~isotope/