使用Python Bottle重定向到带有POST数据的URL
重定向到另一个页面时,是否可以添加POST数据?
Is there any way of adding POST data when redirecting to another page?
我已经构建了一个服务,该服务会将用户重定向回调用该服务时指定的任何页面.问题是由于复杂和错误编写的重写规则等原因,我无法在url上放置任何GET参数.因此,我需要使用POST发送值.无论如何,是否需要在Bottles重定向中添加return(return_url)或在Python中使用其他库?
I've built a service that will redirect the user back to whatever page is specified when the service is called. The problem is I can't put any GET parameters on the url due to complex and badly written rewrite rules etc. so I need to send a value with POST. Is there anyway of adding to Bottles redirect(return_url) or using some other lib in Python?
您可以构建response
,而不是使用bottle的redirect(url)
方法
You may build the response
, instead of using the redirect(url)
method of bottle
from bottle import route, run, response
@post('/wrong')
def wrong():
response.status = 303
response.set_header('Location', '/hello')
return '"key":"val"' # Enter the body here
@route('/hello')
def hello():
return "Hello World!"
run(host='0.0.0.0', port=8080, debug=True)