【问题标题】:How to do simple http redirect using Python?如何使用 Python 进行简单的 http 重定向?
【发布时间】:2011-07-16 07:24:39
【问题描述】:

如何使用 Python 进行简单的 http 重定向? 不使用元

更新:

我在 Apache 的 cgi-bin 目录中使用 Python 2.7.1 作为 CGI。

【问题讨论】:

  • 这完全取决于您使用的网络框架。
  • 对于 http 重定向,您应该向客户端输出带有 location: newUrl 内容的标头。要发送标头,请在您的框架上使用适当的函数。
  • 我在 apache 的 cgi-bin 目录中使用 Python 作为 CGI 脚本。

标签: python http redirect header


【解决方案1】:

使用您当前的设置(CGI apache)进行重定向:

print("Location:http://newurl.com/foobar")
print # to end the CGI response headers.

【讨论】:

  • 收到“脚本头过早结束”错误。 print 语句是我在#!/Python27/python 之后的第一行。
  • 浏览器(Chrome)的url好像没变
  • 虽然这在我桌面上的 Chrome 中运行良好,但在我的 ipad 上却出现 safari 错误,说“重定向太多”......有什么想法吗?我尝试清空 ipad 上的缓存.. 但没有运气。
猜你喜欢
  • 2011-07-14
  • 2017-10-03
  • 2015-06-20
  • 1970-01-01
  • 2016-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多