views:

61

answers:

2

Hi!

In GAE (Python), using the webApp Framework, calling self.redirect('some_url') redirects the user to that URL via the GET method. Is it possible to do a (redirect) via the POST method with some parameters as well?

If possible, how?

Thanks!

A: 

Looks like there's a similar question asked here: http://stackoverflow.com/questions/881086/google-app-engine-self-redirect-post

The answer to that one recommends using the urlfetch.fetch() to do the post.

import urllib

form_fields = {
  "first_name": "Albert",
  "last_name": "Johnson",
  "email_address": "[email protected]"
}
form_data = urllib.urlencode(form_fields)
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
result = urlfetch.fetch(url=url,
                        payload=form_data,
                        method=urlfetch.POST,
                        headers=headers)
Aaron
If you're posting data to yourself, that's a pretty good sign that you're doing something very wrong.
Nick Johnson
+4  A: 

This is not possible due to how most clients implement redirection [1]:

However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method.

So you must use a workaround (like simply calling the method post() from the RequestHandler) or forget the idea.

[1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2

moraes