I have a situation where I would like a view to do a redirect to a URL
that is expecting POST (rather than GET) data. GET would be easy, but
how can I do a POST redirect? The URL I would be redirecting to is not
under my control, so I can't just change it to use GET data.
Thanks,
Bob
Bob,
It entirely depends on what you're trying to do, but as you've
described it, the only way I know of is using JavaScript on the view
page that submits the POST data.
If the target site was under your control, there'd probably be other
ways of doing it.
If I were an expert in JavaScript, I'd give you an example, but I
believe HttpRequest is the place to start.
HTH,
Michael
E.g.
import httplib, urllib
params = urllib.urlencode(request.POST)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Referer": "http://google.com"}
conn = httplib.HTTPConnection("funsite.com:80")
conn.request("POST", "/interesting-place", params, headers)
response = conn.getresponse()
if response.status == 200:
data = response.read()
conn.close()
return HttpResponse(data)
conn.close()
raise Http404
This is a very rough sketch of the shadiness you can do.
Cheers,
Mike Axiak
1: http://docs.python.org/lib/module-httplib.html
On May 3, 4:24 pm, "Bob T." <btaylor...@gmail.com> wrote:
In a RESTful goal, I'd like to do the same and I'm really interested
in any solution.
Regards,
David