I want to write a simple SSL HTTP client in Python and have heard about the Twisted framework.
I need to be able to authenticate with a REST service – so I was thinking I’d just POST a user name and password to the target server. Assuming authentication is successful, the client will receive a cookie.
Will an HTTP client built on Twisted automatically resend the cookie header for each subsequent request, or do I need to do something special? I’ve never used Twisted before.
Thanks
“an HTTP client built on Twisted” will do anything it is built to do – just like, presumably any X built on any Y will do whatever it was built to do. 🙂 So I might suggest that this isn’t the question you really care about the answer to.
Since Twisted 11.1.0, twisted.web.client.CookieAgent accepts a
cookieJarargument which does two things:The soon-to-be-deprecated twisted.web.client.getPage accepts a
cookiesargument behaves similarly.So if you use
CookieAgentthen the cookie will be persisted and sent with subsequent requests, providing the authentication behavior you’re after.You could also do something with
getPagebut given its impending doom you probably shouldn’t.