相关疑难解决方法(0)

解析原始HTTP标头

我有一串原始HTTP,我想表示对象中的字段.有没有办法解析HTTP字符串中的各个标头?

'GET /search?sourceid=chrome&ie=UTF-8&q=ergterst HTTP/1.1\r\nHost: www.google.com\r\nConnection: keep-alive\r\nAccept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\nUser-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.45 Safari/534.13\r\nAccept-Encoding: gzip,deflate,sdch\r\nAvail-Dictionary: GeNLY2f-\r\nAccept-Language: en-US,en;q=0.8\r\n
[...]'
Run Code Online (Sandbox Code Playgroud)

python http-headers

36
推荐指数
3
解决办法
6万
查看次数

Python有一个用于解析HTTP请求和响应的模块吗?

httplib(现在是http.client)和朋友们都有conn.getresponse()和HTTPResponse类,但是conn.getrequest()和HTTPRequest类的服务器端操作似乎缺乏.

我知道BaseHTTPServer和BaseHTTPRequestHandler可以执行此功能,但它们不会公开这些方法以在模块外部使用.

基本上我想要的是BaseHTTPRequestHandler #parse_request是一个静态方法,它返回一个HTTPRequest对象,而不是填充成员变量.

python parsing http

26
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×2

http ×1

http-headers ×1

parsing ×1