重定向到金字塔中的其他网址?

时间:2013-05-28 04:23:10

标签: python post redirect pyramid pylons

我正在铺设双向短信服务。

用户将向SMS服务器平台(www.sms.com)提供的虚拟号码发送短信。该SMS服务器平台将用户SMS数据传递到我的URL(http://www.yourdomainname.com/ReceiveSMS?from=from&message=message

现在我根据“消息”处理用户请求,然后我需要回复此网址 (www.sms.com/optin.php?user=username&pass=password&to=to_mobile_number&message=dynamic_message)

我的问题是如何在处理后将其发布到www.sms.com/optin.php?user=username&pass=password&to=to_mobile_number&message=dynamic_message。

我想做的一种方法是使用HTTPFound。

想知道是否有更有效的方式?

2 个答案:

答案 0 :(得分:2)

在金字塔视图中,您可以向任何渲染器逻辑的侧步返回webob响应。因此,对于重定向,您需要设置状态301/302location header

from webob import Response

@view_config(...)
def your_view(context, request):
    # do stuff
    return Response(status_int=302, location="http://goherenext.com")

HTTPFound只是status hard-coded的响应的子类。

答案 1 :(得分:1)

Requests非常适合发送POST请求

>>> message = 'hello!' # From your inbound SMS
>>> data = {
    'user': 'username', 
    'pass': 'password', 
    'message': message, 
    'to': '123456789'
}
>>> r = requests.post("www.sms.com/optin.php", params=data)
相关问题