开发者

How to decode Get/Post Request headers into tuples using Cherry Py?

开发者 https://www.devze.com 2023-01-14 17:27 出处:网络
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/

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 exampl开发者_JAVA技巧e. Can someone direct me to a more helpful example?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消