如何使用 Cherry Py 将 Get/Post 请求标头解码为元组?

发布于 2024-09-16 18:45:14 字数 250 浏览 3 评论 0原文

好的。至少一位真正乐于助人的人告诉我,他相信从 CherryPy 中解码和解析 GET/POST 请求标头很容易。我去过这里: http://www.cherrypy.org/wiki/BuiltinTools# tools.decode 但它没有给你一个例子。有人可以指导我一个更有用的例子吗?

Ok. I've been told by at least one really helpful individual who believes that its easy to decode and parse a GET/POST request header from within CherryPy. I've been here: http://www.cherrypy.org/wiki/BuiltinTools#tools.decode but it doesn't give you an example. Can someone direct me to a more helpful example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弱骨蛰伏 2024-09-23 18:45:14

我想您的问题包含两个部分:

1)如何获取标头

cherrypy.request.headers是一个字典,您可以像任何其他字典一样提取信息

2)如何使用tools.decode中提供的解码/编码支持

@tools.decode(encoding='ISO-88510-1') 
def decodingFunction(self, data):
    return "%s" % (data, )

这将允许您使用上面的编码集解码字符串。返回的字符串是unicode。将从字典中提取的信息传递给解码和编码函数,您应该能够使用它。

I guess there are two parts embedded to your question:

1) How to get the headers

cherrypy.request.headers is a dict, you can extract information like any other dictionary

2) How to use the decoding / encoding support provided in tools.decode

@tools.decode(encoding='ISO-88510-1') 
def decodingFunction(self, data):
    return "%s" % (data, )

This will allow you to decode a string using above encoding set. The string returned is unicode. Pass the information you extract from the dictionary to your decoding and encoding functions and you should be able to use this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文