Google App Engine self.redirect () POST Method

In GAE (Python), using the webApp platform, calling self.redirect ('some_url') redirects the user to this URL using the GET method. Is it possible (redirect) through the POST method with some parameters?

If possible, how?

Thanks!

+4
source share
3 answers

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

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

So, you should use a workaround (for example, just call the post () method from RequestHandler) or forget the idea.

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

+6
source

You can pass parameters . Here is an example:

Say you have a main page and you want POST to be "/ success". You can usually use this method:

self.redirect('/sucess')

But if you want to pass some parameters from the main page to the /success page, for example, username , you can change the code to this:

self.redirect('/sucess?username=' + username)

Thus, you have successfully passed the username value to the url. On the /success page, you can read and save the value using the following:

username = self.request.get('username')

Finally, you can do your favorite information on the /success page with this simple code:

self.response.out.write('You\'ve succeeded, ' + username + '!')

But , of course, this is not a secure way to pass a password. I want this to help.

0
source

It seems like a similar question has been asked here: Self portrait about Google App Engine .

The answer to this question recommends using urlfetch.fetch () to post a post.

  import urllib

 form_fields = {
   "first_name": "Albert",
   "last_name": "Johnson",
   "email_address": " Albert.Johnson@example.com "
 }
 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)
-1
source

All Articles