Reputation: 47071
In Pyramid, send a request by GET can be done by create URL like this:
@view_config(route_name="test")
def test(request):
return HTTPFound("http://test.com/redirect_to_another_test?a=1")
But it seems that the HTTPFound
can't do that by POST, then how can I do that?
Does anyone have ideas about this? Thanks!
Upvotes: 1
Views: 1890
Reputation: 15690
You can't do this in Pyramid or any other Server-Side Framework or Language.
Your example code isn't showing a form submission, the code is showing a HTTP redirect. It is instructing the Browser to visit another URL, or in other words, telling the browser to resubmit the request.
This Stack Overflow question discusses this same concept, although in ASP not Python - Response.Redirect with POST instead of Get?
If you were to "submit a request" in Pyramid via GET or POST, you would have to use a library like urllib2
, requests
, or similar. In those instances, the libraries would have the Pyramid server act as the "submitter" of the request.
If you want to have the User/web-broswer submit the request by POST, you would have to do some fancy footwork/trickery to make the browser do that.
Possible ways to accomplish that would include:
You can't, in any server side language, tell the browser to resubmit a request by POST. Browsers don't work like that.
You should also know that "Most Browsers" will generally interpret any redirect request to be fetched via GET -- even if the original was a POST. That's not to spec - certain redirect codes are supposed to keep a POST a POST - however browsers don't follow all the specs. There is also no HTTP status code or command to purposefully switch from GET to POST .
Upvotes: 6