【发布时间】:2014-12-24 16:17:55
【问题描述】:
我正在尝试在 Flask 上模拟服务器端表单发布操作。 通过使用 Requests lib 我做后期操作:
@flask_app.route('/hello',methods=['GET','POST'])
def hello():
r = requests.post(
"https://somesite.hello"
, data= {'user': 'bill','pass': 123})
return r.text
#return redirect("https://somesite.hello")
而且它的工作。但是当我通过 html 发布真实表单时,它也会进行重定向。 #1 之后的 url 将是 http://mysite.hello:5000/hello,但我需要来自 #1 的内容,但需要来自 #2 https://somesite.hello 的 url 如何同时执行 1 和 2?谢谢!
更新:
我找到了一些解决方案,我不太喜欢它,因为用户会看到“重定向到计费页面”页面一秒钟。可能有人知道如何请求和重定向以获得一些结果?
@flask_app.route('/hello',methods=['GET','POST'])
def hello():
url = "https://somesite.hello"
return flask_app.make_response("""
<html>
<body onload='document.forms[0].submit()'>
Redirecting to billing page...
<form action='%s' method='post'>
<input type='hidden' name='user' value='%s'>
<input type='hidden' name='pass' value='%s'>
</form>
</body>
</html>
"""%(url
,'bill'
,123))
【问题讨论】:
-
那你打算怎么用r.text呢?
-
我的烧瓶应用程序正在与计费站点通信。要下订单,您必须使用一些数据(shop_id、pass_id、sign)制作第一个 html 表单,并且当您按下提交按钮时(这是我尝试通过烧瓶执行的操作)重定向发生在您所在的 sec 表单可以写卡信息并提交支付。我试着只用一步来做。此 r.text 是计费站点上的第二种形式,但 windows.location 是我的站点。我不知道如何通过烧瓶更改 windows.location。只能通过 jscript 吗?