使用Python Bottle重定向到带有POST数据的URL [英] Redirecting to a url with POST data using Python Bottle

查看:213
本文介绍了使用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)

这篇关于使用Python Bottle重定向到带有POST数据的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆