Pergunta

I must submit two forms at once and I don't want javascript. So I think I can post the form to myself, do my work and then post it on to the third-party payment provider. This is to make the order appear in our datastore. The manual says how to submit a form over HTTP POST but I don't know how to direct the user's browser to this page. Is there a way? Instead of posting the form directly to the third party I thought doing something like this:

  def post(self):
     import urllib
     #do my work
     params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
     f = urllib.urlopen("http://www.thirdparty.com/cgi-bin/query", params)
     #direct the user to the reponse page but how?

It will work to submit the form but the user must be take to the page. Is there a way to achieve this?

Thanks for any help

Foi útil?

Solução

There is something you can do like this:

Get the post form, do stuff on your server, and then return a redirect page that contains a form with same params but action to the remote target.

Then, you can use little js to submit the form automatically, and give something like "Not redirecting? click here" to the user.

So it's not working as what you expected, and it used js too, but I did not find any better way to handle this job. Hope this can help in any way.

Outras dicas

You could use 307 to redirect, which preserves all the POST parameters (you'll need to make sure the POST params your servlet uses are the same as the ones your remote server uses).

self.response.set_status(307)
self.response.headers['Location'] = "http://www.thirdparty.com/cgi-bin/query"

However, not all browsers implement 307 correctly. See here: Response.Redirect with POST instead of Get?

That response is old, so maybe more browsers handle 307 correctly now.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top