在 Python 中检索浏览器标头 [英] Retrieve browser headers in Python
本文介绍了在 Python 中检索浏览器标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在为如何在 Python Tornado 中获取用户的当前浏览器标题信息而画一个空白?例如,在 PHP 中,您可以简单地查看 $_SERVER 数据.Tornado 的替代方案是什么?
I'm currently drawing a blank as how to get the current browser header information for a user in Python Tornado? For example, in PHP you'd simple view the $_SERVER data. What is Tornado's alternative?
注意:我如何获得Tornado 请求的客户端 IP? 并且请求"对我不起作用.
Note: How do I get the client IP of a Tornado request? and the "request" does not work for me.
推荐答案
以下是基于我拥有的服务器的片段,我们在其中从请求中检索了一些标头数据:
Here's a snippet based off of a server I have where we retrieve some header data from the request:
class api(tornado.web.RequestHandler):
def initialize(self, *args, **kwargs):
self.remote_ip = self.request.headers.get('X-Forwarded-For', self.request.headers.get('X-Real-Ip', self.request.remote_ip))
self.using_ssl = (self.request.headers.get('X-Scheme', 'http') == 'https')
def get(self):
self.write("Hello " + ("s" if self.using_ssl else "") + " " + self.remote_ip)
这篇关于在 Python 中检索浏览器标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文