My goal is to come up with a portable urllib2 solution that would POST a form and then redirect the user to what comes out. The POSTing part is simple:
request = urllib2.Request('https://some.site/page', data=urllib.urlencode({'key':'value'}))
response = urllib2.urlopen(request)
Providing data
sets request type to POST. Now, what I suspect all the data I should care about comes from response.info()
& response.geturl()
. I should do a self.redirect(response.geturl())
inside a get(self)
method of webapp.RequestHandler
.
But what should I do with headers? Anything else I've overlooked? Code snippets are highly appreciated. :)
TIA.
EDIT: Here's a naive solution I came up with. Redirects but the remote server shows an error indicating that there's no match to the previously POSTed form:
info = response.info()
for key in info:
self.response.headers[key] = info[key]
self.response.headers['Location'] = response.geturl()
self.response.set_status(302)
self.response.clear()